Make enabling levelling optional
This commit is contained in:
		
					parent
					
						
							
								cc7ea9381c
							
						
					
				
			
			
				commit
				
					
						269c44c065
					
				
			
		
					 4 changed files with 23 additions and 12 deletions
				
			
		|  | @ -13,6 +13,7 @@ public class Config { | |||
|     @SuppressWarnings("unused") private String token; | ||||
|     @SuppressWarnings("unused") private String prefix; | ||||
|     @SuppressWarnings("unused") private DBConfig mariadb; | ||||
|     @SuppressWarnings("unused") private boolean levelling = false; | ||||
| 
 | ||||
|     /** | ||||
|      * Returns the configuration object for this bot | ||||
|  | @ -36,6 +37,7 @@ public class Config { | |||
|         return token; | ||||
|     } | ||||
|     public String getPrefix() { return prefix; } | ||||
|     public boolean getLevelling() { return levelling; } | ||||
| 
 | ||||
|     public DBConfig getDbConfig() { | ||||
|         return mariadb; | ||||
|  |  | |||
|  | @ -31,7 +31,6 @@ public class Doki { | |||
| 
 | ||||
|     public static void start() throws IOException, InterruptedException { | ||||
|         config = Config.readConfig(); | ||||
|         Config.DBConfig dbConfig = config.getDbConfig(); | ||||
| 
 | ||||
|         final JDA jda = JDABuilder.createLight(config.getToken()) | ||||
|                 .setActivity(Activity.customStatus("Banned from everywhere")) | ||||
|  | @ -40,6 +39,8 @@ public class Doki { | |||
|                 .awaitReady(); | ||||
| 
 | ||||
|         // Connect to the DB | ||||
|         if (config.getLevelling()) { | ||||
|             Config.DBConfig dbConfig = config.getDbConfig(); | ||||
|             dataSource.setDriverClassName("org.mariadb.jdbc.Driver"); | ||||
|             dataSource.setUrl("jdbc:mariadb://" + dbConfig.getHost() + ":" + dbConfig.getPortNumber() + "/" + dbConfig.getDatabase()); | ||||
|             dataSource.setUsername(dbConfig.getUser()); | ||||
|  | @ -48,6 +49,7 @@ public class Doki { | |||
|             dataSource.setMaxIdle(5); | ||||
|             dataSource.setMinIdle(2); | ||||
|             dataSource.setInitialSize(10); | ||||
|         } | ||||
| 
 | ||||
|         // Print some information about the bot | ||||
|         log.info("Bot connected as {}", jda.getSelfUser().getAsTag()); | ||||
|  | @ -66,7 +68,11 @@ public class Doki { | |||
|             CommandsBuilder.newBuilder(437970062922612737L) | ||||
|                     .textCommandBuilder(textCommandsBuilder -> textCommandsBuilder.addPrefix(getPrefix())) | ||||
|                     .build(jda, "net.hypr.doki.commands"); //Registering listeners is taken care of by the lib | ||||
|             if (config.getLevelling()) { | ||||
|                 jda.addEventListener(new LevellingListener()); | ||||
|             } else { | ||||
|                 log.info("Levelling is disabled"); | ||||
|             } | ||||
|         } catch (Exception e) { | ||||
|             log.error("Failed to start the bot", e); | ||||
|             System.exit(-1); | ||||
|  |  | |||
|  | @ -64,7 +64,7 @@ public class LevellingListener extends ListenerAdapter { | |||
|         } else { | ||||
|             log.info("No record of user ID {} in server {}, creating blank record", user.getId(), guild.getId()); | ||||
|             try { | ||||
|                 UserRecord rec = DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong(), user.getName()); | ||||
|                 UserRecord rec = DBUtils.createUserRecord(user.getIdLong(), guild.getIdLong()); | ||||
|                 LevellingUtils.incrementXp(log, rec); | ||||
|             } catch (SQLException e) { | ||||
|                 throw new RuntimeException(e); | ||||
|  |  | |||
|  | @ -32,6 +32,9 @@ | |||
|         "password", | ||||
|         "database" | ||||
|       ] | ||||
|     }, | ||||
|     "levelling": { | ||||
|       "type": "boolean" | ||||
|     } | ||||
|   }, | ||||
|   "required": [ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 floppydiskette
				floppydiskette