Browse Source

07.07.2017 -- Gender Module is fully functional, Bug fixes, Stats Module, Systeminfo Module

pull/10/head
Niklas H. 2 years ago
parent
commit
66d147ca24
No known key found for this signature in database
30 changed files with 662 additions and 345 deletions
  1. +2
    -0
      .gitignore
  2. +68
    -15
      lang/lang_en.json
  3. +8
    -4
      src/main/java/discord/BotUtils.java
  4. +4
    -0
      src/main/java/discord/DiscordInit.java
  5. +39
    -14
      src/main/java/discord/ServerControl.java
  6. +87
    -0
      src/main/java/discord/Stats.java
  7. +6
    -16
      src/main/java/discord/SystemInfo.java
  8. +6
    -1
      src/main/java/events/CommandManager.java
  9. +15
    -91
      src/main/java/events/EventListener.java
  10. +7
    -1
      src/main/java/events/Module.java
  11. +13
    -2
      src/main/java/events/RegisterCommands.java
  12. +145
    -0
      src/main/java/events/ServerListener.java
  13. +28
    -6
      src/main/java/events/UserEvents.java
  14. +3
    -3
      src/main/java/main/MoMuOSBMain.java
  15. +7
    -31
      src/main/java/modules/ChangeCommands.java
  16. +6
    -1
      src/main/java/modules/Gamestats.java
  17. +7
    -3
      src/main/java/modules/InfoCommands.java
  18. +6
    -2
      src/main/java/modules/Moderation.java
  19. +7
    -6
      src/main/java/modules/Permission.java
  20. +70
    -47
      src/main/java/modules/RoleManagement.java
  21. +6
    -5
      src/main/java/modules/SearchCommand.java
  22. +66
    -5
      src/main/java/modules/ServerManager.java
  23. +6
    -1
      src/main/java/modules/music/MainMusic.java
  24. +2
    -2
      src/main/java/storage/FileDriver.java
  25. +0
    -76
      src/main/java/storage/LanguageLoader.java
  26. +13
    -0
      src/main/java/storage/LanguageMethod.java
  27. +15
    -6
      src/main/java/util/Console.java
  28. +10
    -5
      src/main/java/util/GetAnnotation.java
  29. +9
    -1
      src/main/java/util/SMB.java
  30. +1
    -1
      src/main/java/util/Utils.java

+ 2
- 0
.gitignore View File

@@ -3,3 +3,5 @@
/config.json
*.log
/permissions.json
/stats.json
/gender.json

+ 68
- 15
lang/lang_en.json View File

@@ -5,20 +5,44 @@
"stats_ram": "Ram Usage",
"permlist_title": "Permission List for Group %1s",
"tofewarguments_error": "You have provided to few arguments. %1s of %2s",
"private_error": "You can not use commands in direct messages",
"search_count": "Result %1s of %2s",
"music_volumechangeerror": "Can\u0027t change volume.",
"setStream_setstream": "Change the Bot Stream",
"login_info": "Bot sign into the server. Please wait until the Bot is ready...",
"removeDisabledServer_setserverenabled": "Removes a Server from List",
"nomanagepermission_error": "The Bot has no Permission to Manage Messages.",
"changeAvatar_setavatar": "Change the Bot Avatar",
"execution_error": "Error occurred on Command Execution: %1s",
"getImage_getImage": "Get Image from Web",
"notdeleted_error": "Message could not be deleted! Error: %1s",
"reloadConfig_reloadconfig": "Reload the Config",
"deletion_error": "Deletion of Messages failed (%1s of %2s) Error: %3s",
"nextImage_next": "Next Image in Resultlist",
"commonmessage_error": "There was an error! Error: %1s",
"listPermToGroup_listperm": "List Permission to Group",
"changeStatus_changestatus": "Change the Status",
"results_end": "You reached the end of results.",
"clearImages_clear": "Clear all Images",
"deleteprivinfo": "Deletion was successfull.",
"disabledserver": "This server is disabled for using the Music Module",
"help_description": "Description",
"notsend_error": "Message could not be sent! Error: %1s",
"help_permission": "Permission",
"props": "Properties",
"help_help": "Display the help",
"search_info": "Search Query",
"setGenderRole_definegenderrole": "Add a User to a specific role",
"stats_user": "Users",
"stats_commands": "Commands",
"setUsername_setusername": "Change the Bot Name",
"parse_error": "The Value cant parsed into a valid format.",
"notchanged_error": "The change Command does not provide resetting.",
"role_remove": "Role %1s removed successful to User %2s",
"role_gender_notfound": "This Gender is not defined.",
"music_notinchannel_user": "You are not in a Voice Channel.",
"help_prefixinfo": "\nThe Prefixes are \nAdmin Prefix: ! \nInfo Prefix: . \nGame Prefix: ~ \nmusic Prefix: $ \n",
"getImage_getImage": "Get Image from Web",
"banServer_banserver": "Ban a Server",
"female_ask": "Are you Male or Female? \nAnswer with the Gender like this: \n@%1s f or @%1s m \n f \u003d female, w \u003d male",
"help_arguments": "Arguments",
"annotation_error": "Invalid Annotation in Module %1s Ex: %2s",
"gender_role_added": "You get the Role: %1s",
"tomanyarguments_error": "You have provided to many arguments. %1s of %2s",
"deleteprivinfo": "Deletion was successfull.",
"shutdowninfo": "The Bot will shutting down in 10 seconds! Bye bye.",
"getServer_getserver": "Get Servers",
"search_result": "Your search Result",
@@ -29,8 +53,8 @@
"stats_shard_ping": "Ping for Shard",
"nopermissions_error": "You have no Permission to use this command.",
"role_add": "Role %1s added successful to User %2s",
"help_noneinfo": "If you want to reset a Value, then type for each argument NA.",
"music_notfound": "Nothing found by %1s.",
"help_noneinfo": "If you want to reset a Value, then type for each argument NA.",
"engine_unknown": "The Search Engine is unknown!",
"leaveServer_leaveserver": "Leaves a specific Server",
"botowner_error": "This command can only be used from Bot Owner.",
@@ -48,14 +72,43 @@
"perm_add_success": "Permission added successful.",
"volumeMusic_volume": "The Bot volume.",
"command_success": "The command was successful!",
"role_gender_add": "Role %1s was added as Gender %2s",
"printProperties_printprop": "Print the Property",
"role_notfound": "The Role was not found.",
"getGameStats_gamestats": "Get Statistics about a Player in a Game",
"perm_add_failed": "Failed to add Permission to group.",
"norolefound": "The Role was not found.",
"stats_title": "General Stats",
"changeprop_error": "This option can\u0027t found in the config file!",
"deleteMessages_deletemessages": "Deletion of Message Amount",
"addPermToGroup_addperm": "Add Permission to Group",
"leaveMusic_leave": "The Bot leaves voice Server",
"searchtoken_google": "Please provide a google search api token.",
"music_add": "Adding to queue: %1s.",
"result_out": "The Result is out of Range.",
"perm_rem_failed": "Failed to remove Permission to group.",
"stats_owner": "Bot Owner",
"joinCommand_join": "The Bot joins voice Server",
"help_command": "Command",
"changeProperty_changeprop": "Change the Property",
"music_add_queue": "Adding to queue %1s (first track of playlist %2s).",
"music_notloaded": "Could not play the choosen song.",
"music_skip": "Skipped to next track.",
"deleteprivateMessages_deleteprivmsg": "Shutdown the bot",
"notdeleted_error": "Message could not be deleted! Error: %1s",
"stats_servercount": "Server Count",
"listPermToGroup_listperm": "List Permission to Group",
"inviteBot_invitebot": "Invites the bot",
"help_title": "All Commands",
"help_alias": "Alias",
"music_notinchannel": "The Bot is not in a voice Channel.",
"notsendpermission_error": "Message could not be send! The Bot has not enough Permissions for [%1s] - #%2s Error: %3s",
"help_help": "Display the help",
"removePermToGroup_removeperm": "Remove Permission to Group",
"stats_stats": "Display the stats",
"nopermissions_error": "You have no Permission to use this command.",
"setGenderRole_definegenderrole": "Add a User to a specific role",
"addPermToGroup_addperm": "Add Permission to Group",
"token_error": "Please provide a token inside of the config.json",
"botowner_error": "This command can only be used from Bot Owner.",
"command_success_wait": "The command was successful. Please wait... Result is generating..."
"stats_shards": "Shards",
"addUsertoRole_addUserRole": "Add a User to a specific role",
"shutdownbot_shutdown": "Shutdown the bot",
"invalid_count_gender": "Your answer is not well formated. \n Look again on the Question.",
"searchImage_search": "Search a Image",
"token_error": "Please provide a token inside of the config.json"
}

+ 8
- 4
src/main/java/discord/BotUtils.java View File

@@ -68,10 +68,12 @@ public class BotUtils implements Fast{
* @param userchannel Channel
* @param message Message
*/
public static IMessage sendPrivMessage(IPrivateChannel userchannel, String message){
public static IMessage sendPrivMessage(IPrivateChannel userchannel, String message, boolean delete){
RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
try{
return userchannel.sendMessage(message);
IMessage messages = userchannel.sendMessage(message);
deleteMessageFromBot(messages, delete);
return messages;
} catch (DiscordException e){
Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
return null;
@@ -110,11 +112,13 @@ public class BotUtils implements Fast{
* @param channel Channel
* @param builder Message as Embeded Builder Instance
*/
public static IMessage sendPrivEmbMessage(IPrivateChannel channel, EmbedBuilder builder){
public static IMessage sendPrivEmbMessage(IPrivateChannel channel, EmbedBuilder builder, boolean delete){
RequestBuffer.RequestFuture<IMessage> feature = RequestBuffer.request(() -> {
try{
Footer.addFooter(builder);
return channel.sendMessage(builder.build());
IMessage message = channel.sendMessage(builder.build());
deleteMessageFromBot(message, delete);
return message;
} catch (DiscordException e){
Console.error(String.format(LANG.getTranslation("notsend_error"), e.getMessage()));
return null;

+ 4
- 0
src/main/java/discord/DiscordInit.java View File

@@ -1,6 +1,8 @@
package discord;

import events.EventListener;
import events.ServerListener;
import events.UserEvents;
import util.Fast;
import sx.blah.discord.api.IDiscordClient;
import util.Console;
@@ -37,6 +39,8 @@ public class DiscordInit implements Fast{
Console.println(LANG.getTranslation("login_info"));
cli = BotUtils.getBuiltDiscordClient(token);
cli.getDispatcher().registerListener(EventListener.getInstance());
cli.getDispatcher().registerListener(ServerListener.getInstance());
cli.getDispatcher().registerListener(UserEvents.getInstance());
cli.login();
BOT = cli;
}

+ 39
- 14
src/main/java/discord/ServerControl.java View File

@@ -7,6 +7,7 @@ import util.Fast;
import util.Utils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

/**
@@ -14,8 +15,10 @@ import java.util.HashMap;
* Copyright 2017
*/
public class ServerControl implements Fast{
private static ArrayList<String> defaultlist;
public String MUSIC_MODULE = "music";
public String JOIN_MODULE = "joinevent";
public String JOIN_MODULE = "join";
public String BAN_MODULE = "banned";
private static HashMap<String, ArrayList<String>> disabledlist = new HashMap<>();
private static ServerControl instance;

@@ -23,6 +26,9 @@ public class ServerControl implements Fast{
if (instance == null) {
instance = new ServerControl();
}
disabledlist.put(instance.MUSIC_MODULE, new ArrayList<>());
disabledlist.put(instance.BAN_MODULE, new ArrayList<>());
disabledlist.put(instance.JOIN_MODULE, new ArrayList<>());
return instance;
}

@@ -30,10 +36,12 @@ public class ServerControl implements Fast{
public void addDisabledServer(IGuild guild, boolean newserver, String module) {
try {
if (disabledlist.get(module) != null && !disabledlist.get(module).contains(guild.getStringID())) {
disabledlist.get(module).add(guild.getStringID());
if (newserver) {
Console.debug("Server added as New");
disabledlist.get(module).add(guild.getStringID());
DRIVER.setProperty(DRIVER.CONFIG, module+"_disabled_servers", disabledlist.get(module));
} else {
Console.debug("Server exists");
DRIVER.getProperty(DRIVER.CONFIG, module+"_disabled_servers", disabledlist.get(module));
}
Console.debug("Saved: |"+guild.getStringID()+" "+module+" "+guild.getStringID());
@@ -43,25 +51,33 @@ public class ServerControl implements Fast{
ex.printStackTrace();
}
}
public void loadSavedServer(String module) {
disabledlist.computeIfAbsent(module, k -> new ArrayList<>());
disabledlist.get(module).clear();
JSONArray jArray = Utils.objectToJSONArray(DRIVER.getProperty(DRIVER.CONFIG, module+"_disabled_servers", new ArrayList<String>()));
if (jArray != null) {
for (int i = 0; i < jArray.length(); i++) {
disabledlist.get(module).add(jArray.get(i).toString());
Console.debug("Load: |"+module+" "+jArray.get(i).toString());
public void addBannedServer(String guild) {
try {
if (disabledlist.get(BAN_MODULE) != null && !disabledlist.get(BAN_MODULE).contains(guild)) {
disabledlist.get(BAN_MODULE).add(guild);
Console.debug("Server added as New");
DRIVER.setProperty(DRIVER.CONFIG, BAN_MODULE+"_disabled_servers", disabledlist.get(BAN_MODULE));
Console.debug("Saved: |"+guild+" "+BAN_MODULE+" "+guild);
}
} catch (Exception ex) {
Console.error("Cant add Server");
ex.printStackTrace();
}
}
public void removeDisabledServer(IGuild guild, String module) {
try {
JSONArray jArray = Utils.objectToJSONArray(DRIVER.getProperty(DRIVER.CONFIG, module+"_disabled_servers", new ArrayList<String>()));
public void loadSavedServer(String module) {
disabledlist.get(module).clear();
if (DRIVER.hasKey(DRIVER.CONFIG, module+"_disabled_servers")) {
JSONArray jArray = Utils.objectToJSONArray(DRIVER.getPropertyOnly(DRIVER.CONFIG, module + "_disabled_servers"));
if (jArray != null) {
for (int i = 0; i < jArray.length(); i++) {
disabledlist.get(module).add(jArray.get(i).toString());
Console.debug("Load: |" + module + " " + jArray.get(i).toString());
}
}
}
}
public void removeDisabledServer(IGuild guild, String module) {
try {
if (disabledlist.get(module) != null && disabledlist.get(module).contains(guild.getStringID())) {
disabledlist.get(module).remove(guild.getStringID());
DRIVER.setProperty(DRIVER.CONFIG, module+"_disabled_servers", disabledlist.get(module));
@@ -72,8 +88,17 @@ public class ServerControl implements Fast{
ex.printStackTrace();
}
}
public boolean checkServerisBanned(IGuild guild) {
if (disabledlist.get(BAN_MODULE) != null && guild != null) {
if(disabledlist.get(BAN_MODULE).contains(guild.getStringID())) {
Console.debug("Found: |" + guild.getStringID() + " " + BAN_MODULE + " " + guild.getStringID());
return true;
}
}
return false;
}
public ArrayList<String> getDisabledlist(String module) {
disabledlist.computeIfAbsent(module, k -> new ArrayList<>());
Console.debug(disabledlist.get(JOIN_MODULE).size()+" "+disabledlist.get(MUSIC_MODULE).size());
return disabledlist.get(module);
}
}

+ 87
- 0
src/main/java/discord/Stats.java View File

@@ -0,0 +1,87 @@
package discord;

import org.json.JSONArray;
import sx.blah.discord.handle.obj.IGuild;
import util.Console;
import util.Fast;
import util.Utils;

import java.util.ArrayList;

/**
* Created by N.Hartmann on 07.07.2017.
* Copyright 2017
*/
public class Stats implements Fast {
private static int joineduser = 0;
private static int joinedserver = 0;
private static int messages = 0;
private static int commands = 0;
private static ArrayList<String> serverlist = new ArrayList<>();
private static String STATS = "stats.json";


public static void addUser() {
joineduser = joineduser + 1;
}

public static void addServer(IGuild server) {
if (!serverlist.contains(server.getStringID())) {
joinedserver = joinedserver + 1;
serverlist.add(server.getStringID());
}
}

public static void addMessages() {
messages = messages + 1;
}

public static void addCommands() {
commands = commands + 1;
}

public static String getStats() {
return "Stats: \n" +
"Server: "+joinedserver+" \n"+
"User: "+joineduser+" \n"+
"Messages: "+messages+" \n"+
"Commands: "+commands+" \n";
}


public static void saveStats() {
try {
DRIVER.setProperty(STATS, "joinedUser", joineduser);
DRIVER.setProperty(STATS, "joinedServer", joinedserver);
DRIVER.setProperty(STATS, "messages", messages);
DRIVER.setProperty(STATS, "commands", commands);
DRIVER.setProperty(STATS, "server", serverlist);
DRIVER.saveJson();
Console.println(getStats());
} catch (Exception ex) {
ex.printStackTrace();
}
}

public static void loadStats() {
try {
DRIVER.createNewFile(STATS);
joineduser = Integer.valueOf(DRIVER.getProperty(STATS, "joinedUser", joineduser).toString());
joinedserver = Integer.valueOf(DRIVER.getProperty(STATS, "joinedServer", joinedserver).toString());
JSONArray jArray = Utils.objectToJSONArray(DRIVER.getPropertyOnly(STATS, "server"));
if (jArray != null) {
for (int i = 0; i < jArray.length(); i++) {
serverlist.add(jArray.get(i).toString());
Console.debug("Load: |" + jArray.get(i).toString());
}
}
messages = Integer.valueOf(DRIVER.getProperty(STATS, "messages", messages).toString());
commands = Integer.valueOf(DRIVER.getProperty(STATS, "commands", commands).toString());
Console.println(getStats());
}catch (Exception ex) {
ex.printStackTrace();
}
}


}

+ 6
- 16
src/main/java/discord/SystemInfo.java View File

@@ -44,17 +44,8 @@ public class SystemInfo {
long maxMemory = runtime.maxMemory();
long allocatedMemory = runtime.totalMemory();
long freeMemory = runtime.freeMemory();
sb.append("Free memory: ");
sb.append(format.format(freeMemory / 1024));
sb.append("\n");
sb.append("Allocated memory: ");
sb.append(format.format(allocatedMemory / 1024));
sb.append("\n");
sb.append("Max memory: ");
sb.append(format.format(maxMemory / 1024));
sb.append("\n");
sb.append("Total free memory: ");
sb.append(format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024));
sb.append("Used Memory: |");
sb.append(getUsedMem());
sb.append("\n");
return sb.toString();

@@ -62,16 +53,15 @@ public class SystemInfo {

private String OsInfo() {
StringBuilder sb = new StringBuilder();
sb.append("OS: ");
sb.append("\nOS: |");
sb.append(this.OSname());
sb.append("\n");
sb.append("Version: ");
sb.append("Version: |");
sb.append(this.OSversion());
sb.append("\n");
sb.append(": ");
sb.append(" : ");
sb.append(this.OsArch());
sb.append("\n");
sb.append("Available processors (cores): ");
sb.append("CPU Cores: |");
sb.append(runtime.availableProcessors());
sb.append("\n");
return sb.toString();

+ 6
- 1
src/main/java/events/CommandManager.java View File

@@ -1,6 +1,7 @@
package events;

import org.tritonus.share.ArraySet;
import storage.LanguageMethod;
import util.Console;
import util.GetAnnotation;

@@ -16,6 +17,10 @@ import java.util.Set;
public class CommandManager {
private HashMap<Command, Method> modules = new HashMap<>();
private HashMap<Command, Module> instances = new HashMap<>();

public HashMap<LanguageMethod, Method> languages = new HashMap<>();
public HashMap<LanguageMethod, Module> langinstances = new HashMap<>();

private static ArrayList<String> prefixe = new ArrayList<>();

private static CommandManager instance;
@@ -28,7 +33,7 @@ public class CommandManager {
}

public void registerCommand(Class module, Module instance) {
HashMap<Command, Method> annotations = GetAnnotation.getCommandAnnotation(module);
HashMap<Command, Method> annotations = GetAnnotation.getCommandAnnotation(module, instance);
for (Command anno : annotations.keySet()) {
if (!getAllCommandsAsString().contains(anno.command())) {
if (!getAllAliasAsString().contains(anno.alias())) {

+ 15
- 91
src/main/java/events/EventListener.java View File

@@ -3,6 +3,7 @@ package events;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import discord.BotUtils;
import discord.ServerControl;
import discord.Stats;
import discord.SystemInfo;
import modules.RoleManagement;
import sx.blah.discord.handle.impl.events.guild.GuildCreateEvent;
@@ -22,7 +23,6 @@ import java.util.*;
*/
public class EventListener implements Fast {
private static EventListener instance;
private static boolean running = false;
private String botprefix;
private String[] args;
private String commandstring;
@@ -49,6 +49,11 @@ public class EventListener implements Fast {
public void onMessageReceivedEvent(MessageReceivedEvent event) { // This method is NOT called because it doesn't have the @EventSubscriber annotation
new Thread(() -> {
try {
Stats.addMessages();
if (SERVER_CONTROL.checkServerisBanned(event.getGuild())) {
Console.println("Leave Banned Server: "+event.getGuild().getName());
//event.getGuild().leave();
}
//Check if Channel is Private (DM)
//Console.debug("MI: "+event.getGuild().getStringID()+" "+event.getChannel().getName()+" "+event.getAuthor().getName());
if (!event.getChannel().isPrivate()) {
@@ -58,6 +63,7 @@ public class EventListener implements Fast {
setArgsAndPrefix(messageparts, message);
Command command = COMMAND.getCommandByName(commandstring);
if (command != null && (botprefix + command.prefix()).equalsIgnoreCase(prefix)) {
Stats.addCommands();
Console.debug(Console.recievedprefix + "Message: " + message + " Author: " + event.getAuthor().getName() + " Channel: " + event.getChannel().getName());
//Check if Invoke Messages should be deleted
if (DRIVER.getProperty(DRIVER.CONFIG, "deleteinvokes", true).equals(true)) {
@@ -66,7 +72,7 @@ public class EventListener implements Fast {
event.getMessage().delete();
} else {
Console.debug(Console.sendprefix + "Message not deleted: [" + message + "] -- nopermissions");
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), SMB.shortMessage(LANG.ERROR + LANG.getTranslation("nomanagepermission_error")));
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), SMB.shortMessage(LANG.ERROR + LANG.getTranslation("nomanagepermission_error")), true);
}
}
if (PERM.hasPermission(event.getAuthor(), event.getGuild(), command.permission())) {
@@ -78,10 +84,14 @@ public class EventListener implements Fast {
}
} else {
if (event.getMessage().getMentions().contains(INIT.BOT.getOurUser())) {
setArgsAndPrefix(event.getMessage().getContent().split(" "), event.getMessage().getContent());
UserEvents.getInstance().setGenderRole(event, args[0]);
String[] messageparts = event.getMessage().getContent().trim().split(" ");
if (messageparts.length == 2) {
UserEvents.getInstance().setGenderRole(event, messageparts[1]);
} else {
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), LANG.ERROR + LANG.getTranslation("invalid_count_gender"), true);
}
} else {
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), LANG.ERROR + LANG.getTranslation("private_error"));
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), LANG.ERROR + LANG.getTranslation("private_error"), true);
}
}
} catch (Exception ex) {
@@ -146,91 +156,5 @@ public class EventListener implements Fast {
*
* @param event The Event
*/
@EventSubscriber
public void onReadyEvent(ReadyEvent event) { // This method is called when the ReadyEvent is dispatched
Console.println("Bot login success");
Console.println("Shards: " + INIT.BOT.getShardCount());
StringBuilder serverstr = new StringBuilder();
int count = 1;
for (IGuild server : INIT.BOT.getGuilds()) {
serverstr.append("\n")
.append(count)
.append(". [")
.append(server.getName())
.append(" ")
.append(server.getStringID())
.append("]");
count++;
}
Console.println("Servers: " + serverstr);
RegisterCommands.registerAll();
Console.println("Loading Permissions from SaveFile");
PERM.loadPermissions(INIT.BOT.getGuilds());
PERM.setDefaultPermissions(INIT.BOT.getGuilds(), false);
INIT.BOT.changePlayingText(DRIVER.getPropertyOnly(DRIVER.CONFIG, "defaultplaying").toString());
INIT.BOT.changeUsername(DRIVER.getPropertyOnly(DRIVER.CONFIG, "defaultUsername").toString());
Console.println("Loading Command Descriptions");
for (Command command : COMMAND.getAllCommands()) {
LANG.getMethodDescription(command);
}
Console.println("Register Audioprovider");
AudioSourceManagers.registerRemoteSources(MainMusic.playerManager);
AudioSourceManagers.registerLocalSource(MainMusic.playerManager);

RoleManagement.loadGenders();

saveGuilds();
Console.println("====================================Bot Status========================================");
INIT.BOT.getShards().forEach(iShard -> {
Console.println("Shard "+iShard.getInfo()[0]+": "+iShard.isReady()+" Servers: "+iShard.getGuilds().size()+" Ping: "+iShard.getResponseTime());
});
Console.println("Username: "+INIT.BOT.getOurUser().getName());
Console.println("PlayText: "+INIT.BOT.getOurUser().getPresence().getPlayingText().get());
Console.println("Status: "+INIT.BOT.getOurUser().getPresence().getStatus());
Console.println("Streaming: "+INIT.BOT.getOurUser().getPresence().getStreamingUrl());
SystemInfo info = new SystemInfo();
Console.println("SystemInfo: "+info.Info()+"\n");
Command helpcommand = COMMAND.getCommandByName("help");
Console.println("Type "+ DRIVER.getPropertyOnly(DRIVER.CONFIG, "botprefix").toString()+helpcommand.prefix()+helpcommand.command()+" for getting help.");
Console.println("====================================Bot Start completed===============================");
running = true;
}

@EventSubscriber
public void onGuildCreate(GuildCreateEvent event) {
Console.println("==================NEW SERVER |" + event.getGuild().getName() + "| " + event.getGuild().getStringID());
if (running) {
Console.debug("Adding Permission for new Server");
List<IGuild> server = new ArrayList<>();
server.add(event.getGuild());
PERM.setDefaultPermissions(server, true);
Console.debug("Adding Disabled Server for new Server");
saveGuild(event.getGuild());
DRIVER.saveJson();
}
Console.debug("===================new Server added====");
}

public void saveGuilds() {
for (IGuild server : INIT.BOT.getGuilds()) {
saveGuild(server);
}
DRIVER.saveJson();
}
public void saveGuild(IGuild server) {
if (DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.MUSIC_MODULE + "_disabled_default") || DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.JOIN_MODULE + "_disabled_default")) {
if (DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.MUSIC_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, running, SERVER_CONTROL.MUSIC_MODULE);
}
if (DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.JOIN_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, running, SERVER_CONTROL.JOIN_MODULE);
}
if (!DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.MUSIC_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, true, SERVER_CONTROL.MUSIC_MODULE);
}
if (!DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.JOIN_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, true, SERVER_CONTROL.JOIN_MODULE);
}
}
}
}

+ 7
- 1
src/main/java/events/Module.java View File

@@ -1,10 +1,16 @@
package events;

import storage.LanguageInterface;
import util.Console;
import util.Fast;

/**
* Created by N.Hartmann on 28.06.2017.
* Copyright 2017
*/
public class Module implements Fast {
public class Module implements Fast, LanguageInterface {
@Override
public void setdefaultLanguage() {
Console.error("No Language");
}
}

+ 13
- 2
src/main/java/events/RegisterCommands.java View File

@@ -1,15 +1,16 @@
package events;

import modules.*;
import util.Fast;
import modules.music.MainMusic;
import storage.LanguageMethod;
import util.Console;
import util.Fast;

/**
* Created by N.Hartmann on 28.06.2017.
* Copyright 2017
*/
class RegisterCommands implements Fast{
public class RegisterCommands implements Fast{
/**
* Commands Registration
*/
@@ -24,7 +25,17 @@ class RegisterCommands implements Fast{
COMMAND.registerCommand(Permission.class, new Permission());
COMMAND.registerCommand(Gamestats.class, new Gamestats());
COMMAND.registerCommand(RoleManagement.class, new RoleManagement());
COMMAND.registerCommand(ServerManager.class, new ServerManager());

try {
for (LanguageMethod language : COMMAND.languages.keySet()) {
Console.debug("Moduleclass: "+COMMAND.langinstances.get(language).getClass().getName());
COMMAND.langinstances.get(language).setdefaultLanguage();
}
}catch (Exception ex) {
ex.printStackTrace();
System.exit(0);
}
DRIVER.saveJson();



+ 145
- 0
src/main/java/events/ServerListener.java View File

@@ -0,0 +1,145 @@
package events;

import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import discord.Stats;
import discord.SystemInfo;
import modules.RoleManagement;
import modules.music.MainMusic;
import sx.blah.discord.api.events.EventSubscriber;
import sx.blah.discord.handle.impl.events.ReadyEvent;
import sx.blah.discord.handle.impl.events.guild.GuildCreateEvent;
import sx.blah.discord.handle.obj.IGuild;
import util.Console;
import util.Fast;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
* Created by N.Hartmann on 07.07.2017.
* Copyright 2017
*/
public class ServerListener implements Fast{

private static boolean running = false;

private static ServerListener instance;

public static ServerListener getInstance() {
if (instance == null) {
instance = new ServerListener();
}
return instance;
}

@EventSubscriber
public void onReadyEvent(ReadyEvent event) { // This method is called when the ReadyEvent is dispatched
Console.println("Bot login success");
Console.println("Shards: " + INIT.BOT.getShardCount());
StringBuilder serverstr = new StringBuilder();
int count = 1;
for (IGuild server : INIT.BOT.getGuilds()) {
serverstr.append("\n")
.append(count)
.append(". [")
.append(server.getName())
.append(" ")
.append(server.getStringID())
.append("]");
count++;
}
Console.println("Servers: " + serverstr);
RegisterCommands.registerAll();
Console.println("Loading Permissions from SaveFile");
PERM.loadPermissions(INIT.BOT.getGuilds());
PERM.setDefaultPermissions(INIT.BOT.getGuilds(), false);
INIT.BOT.changePlayingText(DRIVER.getPropertyOnly(DRIVER.CONFIG, "defaultplaying").toString());
INIT.BOT.changeUsername(DRIVER.getPropertyOnly(DRIVER.CONFIG, "defaultUsername").toString());
Console.println("Loading Command Descriptions");
for (Command command : COMMAND.getAllCommands()) {
LANG.getMethodDescription(command);
}
Console.println("Register Audioprovider");
AudioSourceManagers.registerRemoteSources(MainMusic.playerManager);
AudioSourceManagers.registerLocalSource(MainMusic.playerManager);

RoleManagement.loadGenders();

saveGuilds();
Console.println("====================================Bot Status========================================");
INIT.BOT.getShards().forEach(iShard -> {
Console.println("Shard "+iShard.getInfo()[0]+": "+iShard.isReady()+" Servers: "+iShard.getGuilds().size()+" Ping: "+iShard.getResponseTime());
});
Optional stream = INIT.BOT.getOurUser().getPresence().getStreamingUrl();
Optional playtext = INIT.BOT.getOurUser().getPresence().getPlayingText();
Console.println("Username: "+INIT.BOT.getOurUser().getName());
Console.println("Status: "+INIT.BOT.getOurUser().getPresence().getStatus());
if (stream.isPresent()) {
Console.println("Streaming: "+stream.get());
} else {
Console.println("Streaming: OFFLINE");
}
if (playtext.isPresent()) {
Console.println("Playing: "+playtext.get());
} else {
Console.println("Playing: NOTHING");
}

SystemInfo info = new SystemInfo();
Console.println("SystemInfo: "+info.Info()+"\n");
Command helpcommand = COMMAND.getCommandByName("help");
Console.println("Type "+ DRIVER.getPropertyOnly(DRIVER.CONFIG, "botprefix").toString()+helpcommand.prefix()+helpcommand.command()+" for getting help.");
Console.println("====================================Bot Start completed===============================");
running = true;
}

@EventSubscriber
public void onGuildCreate(GuildCreateEvent event) {
Console.println("==================NEW SERVER |" + event.getGuild().getName() + "| " + event.getGuild().getStringID());
if (SERVER_CONTROL.checkServerisBanned(event.getGuild())) {
Console.println("Leave Banned Server: "+event.getGuild().getName());
//event.getGuild().leave();
} else {
if (running) {
Stats.addServer(event.getGuild());
Console.debug("Adding Permission for new Server");
List<IGuild> server = new ArrayList<>();
server.add(event.getGuild());
PERM.setDefaultPermissions(server, true);
Console.debug("Adding Disabled Server for new Server");
saveGuild(event.getGuild());
DRIVER.saveJson();
}
Console.debug("===================new Server added====");
}
}

private void saveGuilds() {
Console.println("Server init");
SERVER_CONTROL.loadSavedServer(SERVER_CONTROL.MUSIC_MODULE);
SERVER_CONTROL.loadSavedServer(SERVER_CONTROL.JOIN_MODULE);
SERVER_CONTROL.loadSavedServer(SERVER_CONTROL.BAN_MODULE);

for (IGuild server : INIT.BOT.getGuilds()) {
saveGuild(server);
}
DRIVER.saveJson();
}
private void saveGuild(IGuild server) {
if (DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.MUSIC_MODULE + "_disabled_default") || DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.JOIN_MODULE + "_disabled_default")) {
if (DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.MUSIC_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, running, SERVER_CONTROL.MUSIC_MODULE);
}
if (DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.JOIN_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, running, SERVER_CONTROL.JOIN_MODULE);
}
if (!DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.MUSIC_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, true, SERVER_CONTROL.MUSIC_MODULE);
}
if (!DRIVER.hasKey(DRIVER.CONFIG, SERVER_CONTROL.JOIN_MODULE + "_disabled_servers")) {
SERVER_CONTROL.addDisabledServer(server, true, SERVER_CONTROL.JOIN_MODULE);
}
}
}
}

+ 28
- 6
src/main/java/events/UserEvents.java View File

@@ -1,16 +1,24 @@
package events;

import com.koloboke.collect.impl.hash.Hash;
import discord.BotUtils;
import discord.ServerControl;
import discord.Stats;
import modules.RoleManagement;
import sx.blah.discord.api.events.EventSubscriber;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.impl.events.guild.member.UserJoinEvent;
import sx.blah.discord.handle.obj.IGuild;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.EmbedBuilder;
import util.Console;
import util.Fast;
import util.SMB;

import java.awt.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

/**
@@ -20,6 +28,8 @@ import java.util.List;
public class UserEvents implements Fast{
private static UserEvents instance;

private static HashMap<IUser, IGuild> user = new HashMap<>();

public static UserEvents getInstance() {
if (instance == null) {
instance = new UserEvents();
@@ -29,9 +39,12 @@ public class UserEvents implements Fast{

@EventSubscriber
public void onUserJoin(UserJoinEvent event) {
if (!SERVER_CONTROL.getDisabledlist(SERVER_CONTROL.JOIN_MODULE).contains(event.getGuild().getStringID()) && DRIVER.getPropertyOnly(DRIVER.CONFIG, "genderroles").equals(true)) {
Console.debug(Console.recievedprefix+"User joined: "+event.getUser().getName()+" to Server: "+event.getGuild().getName());
Stats.addUser();
if (!SERVER_CONTROL.getDisabledlist(SERVER_CONTROL.JOIN_MODULE).contains(event.getGuild().getStringID()) || DRIVER.getPropertyOnly(DRIVER.CONFIG, "genderroles").equals(true)) {
if (RoleManagement.isGenderdefined(event.getGuild())) {
BotUtils.sendPrivEmbMessage(event.getUser().getOrCreatePMChannel(), SMB.shortMessage(LANG.getTranslation("female_ask")));
user.put(event.getUser(), event.getGuild());
BotUtils.sendPrivEmbMessage(event.getUser().getOrCreatePMChannel(), SMB.shortMessage(String.format(LANG.getTranslation("female_ask"), INIT.BOT.getOurUser().getName())), false);
} else {
Console.debug("Server has not valid Gender.");
}
@@ -39,10 +52,19 @@ public class UserEvents implements Fast{
}

public void setGenderRole(MessageReceivedEvent event, String gender) {
List<IRole> roles = RoleManagement.getRoleforGender(event.getGuild(), gender);
for (IRole role: roles) {
event.getAuthor().addRole(role);
List<IRole> roles = RoleManagement.getRoleforGender(user.get(event.getAuthor()), gender);
StringBuilder rolename = new StringBuilder();
if (roles != null) {
for (IRole role : roles) {
rolename.append(role.getName()).append(",");
event.getAuthor().addRole(role);
}
if (roles.size() > 0) {
user.remove(event.getAuthor());
}
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), SMB.shortMessage(String.format(LANG.getTranslation("gender_role_added"), rolename.toString())), true);
} else {
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), SMB.shortMessage(LANG.getTranslation("role_notfound")), true);
}
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), SMB.shortMessage("gender_role_added"));
}
}

+ 3
- 3
src/main/java/main/MoMuOSBMain.java View File

@@ -1,6 +1,7 @@
package main;

import discord.DiscordInit;
import discord.Stats;
import modules.RoleManagement;
import storage.ConfigLoader;
import util.Console;
@@ -30,8 +31,7 @@ public class MoMuOSBMain implements Fast {
LANG.setDefaultLanguage();
Console.println("Language loading complete!");

SERVER_CONTROL.loadSavedServer(SERVER_CONTROL.MUSIC_MODULE);
SERVER_CONTROL.loadSavedServer(SERVER_CONTROL.JOIN_MODULE);
Stats.loadStats();

Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
@@ -52,7 +52,7 @@ public class MoMuOSBMain implements Fast {
*/
public static void shutdown() {
Console.println("====================================Bot shutting down...==============================");
Stats.saveStats();
RoleManagement.saveGenders();

if (INIT.BOT != null && INIT.BOT.isLoggedIn()) {

+ 7
- 31
src/main/java/modules/ChangeCommands.java View File

@@ -4,15 +4,13 @@ import discord.BotUtils;
import events.Command;
import events.Module;
import storage.LanguageInterface;
import storage.LanguageMethod;
import sx.blah.discord.handle.obj.IGuild;
import util.Globals;
import util.*;
import org.apache.commons.lang3.math.NumberUtils;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.util.EmbedBuilder;
import sx.blah.discord.util.Image;
import util.Markdown;
import util.SMB;
import util.Utils;

import java.awt.*;
import java.text.NumberFormat;
@@ -23,7 +21,7 @@ import java.util.List;
* Created by N.Hartmann on 28.06.2017.
* Copyright 2017
*/
public class ChangeCommands extends Module implements LanguageInterface {
public class ChangeCommands extends Module implements Fast {

/**
* Change the Avatar of the Bot
@@ -183,7 +181,7 @@ public class ChangeCommands extends Module implements LanguageInterface {
}
builder.appendField(LANG.getTranslation("props"), stringBuilder.toString(), false);

BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builder);
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builder, false);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS+LANG.getTranslation("command_success")), true);
return true;
}
@@ -258,31 +256,6 @@ public class ChangeCommands extends Module implements LanguageInterface {
return true;
}

@Command(
command = "getserver",
arguments = {},
description = "Get Servers",
alias = "gets",
permission = Globals.BOT_OWNER,
prefix = Globals.ADMIN_PREFIX
)
public boolean getServer(MessageReceivedEvent event, String[] args) {
try {
List<IGuild> server = INIT.BOT.getGuilds();
EmbedBuilder builder = new EmbedBuilder();
builder.withTitle("ServerList");
builder.withDescription(Markdown.bold("Size: "+server.size())+" \n");
for (IGuild serverinst: server) {
builder.appendDesc(Markdown.bold(serverinst.getName())+": "+serverinst.getStringID()+" \n");
}
builder.withColor(Color.green);
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builder);
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.SUCCESS+LANG.getTranslation("commonmessage_error"), ex.getMessage())), true);
}
return true;
}

@Command(
command = "reloadconfig",
arguments = {},
@@ -301,6 +274,9 @@ public class ChangeCommands extends Module implements LanguageInterface {
return true;
}

@LanguageMethod(
languagestringcount = 4
)
@Override
public void setdefaultLanguage() {
//Changes

+ 6
- 1
src/main/java/modules/Gamestats.java View File

@@ -5,10 +5,12 @@ import events.Command;
import events.Module;
import org.json.JSONObject;
import storage.LanguageInterface;
import storage.LanguageMethod;
import storage.RestRequest;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.util.EmbedBuilder;
import util.Console;
import util.Fast;
import util.SMB;
import util.Utils;

@@ -18,7 +20,7 @@ import java.awt.*;
* Created by N.Hartmann on 04.07.2017.
* Copyright 2017
*/
public class Gamestats extends Module implements LanguageInterface{
public class Gamestats extends Module implements Fast{
@Command(
command = "gamestats",
alias = "gstats",
@@ -53,6 +55,9 @@ public class Gamestats extends Module implements LanguageInterface{
}
}

@LanguageMethod(
languagestringcount = 0
)
@Override
public void setdefaultLanguage() {


+ 7
- 3
src/main/java/modules/InfoCommands.java View File

@@ -6,6 +6,7 @@ import discord.SystemInfo;
import events.Command;
import events.Module;
import storage.LanguageInterface;
import storage.LanguageMethod;
import util.*;
import main.MoMuOSBMain;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
@@ -25,7 +26,7 @@ import java.util.EnumSet;
* Created by N.Hartmann on 28.06.2017.
* Copyright 2017
*/
public class InfoCommands extends Module implements Fast, LanguageInterface {
public class InfoCommands extends Module implements Fast {

/**
* Help Command
@@ -46,7 +47,7 @@ public class InfoCommands extends Module implements Fast, LanguageInterface {
new Thread(() -> {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("command_success_wait")), true);
for (EmbedBuilder builder : genbuildHelp(event)) {
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builder);
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builder, false);
}
}).start();
return true;
@@ -71,7 +72,7 @@ public class InfoCommands extends Module implements Fast, LanguageInterface {
if (event.getAuthor().equals(DiscordInit.getInstance().getDiscordClient().getApplicationOwner())) {
EnumSet<Permissions> permissions = EnumSet.allOf(Permissions.class);
BotInviteBuilder builder = new BotInviteBuilder(INIT.BOT).withPermissions(permissions);
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), builder.build());
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), builder.build(), false);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("command_success")), true);
} else {
BotUtils.sendMessage(event.getChannel(), LANG.ERROR + LANG.getTranslation("botowner_error"), true);
@@ -155,6 +156,9 @@ public class InfoCommands extends Module implements Fast, LanguageInterface {
return builders;
}

@LanguageMethod(
languagestringcount = 16
)
@Override
public void setdefaultLanguage() {
//Stats Command

+ 6
- 2
src/main/java/modules/Moderation.java View File

@@ -4,7 +4,9 @@ import discord.BotUtils;
import events.Command;
import events.Module;
import storage.LanguageInterface;
import storage.LanguageMethod;
import sx.blah.discord.handle.obj.IPrivateChannel;
import util.Fast;
import util.Globals;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IChannel;
@@ -19,7 +21,7 @@ import java.util.List;
* Created by N.Hartmann on 28.06.2017.
* Copyright 2017
*/
public class Moderation extends Module implements LanguageInterface{
public class Moderation extends Module implements Fast{

/**
* Deletes a List Message
@@ -154,7 +156,9 @@ public class Moderation extends Module implements LanguageInterface{
}).start();
return true;
}

@LanguageMethod(
languagestringcount = 1
)
@Override
public void setdefaultLanguage() {
//Deletion

+ 7
- 6
src/main/java/modules/Permission.java View File

@@ -4,13 +4,11 @@ import discord.BotUtils;
import events.Command;
import events.Module;
import storage.LanguageInterface;
import storage.LanguageMethod;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.util.EmbedBuilder;
import util.Console;
import util.Globals;
import util.SMB;
import util.Utils;
import util.*;

import java.awt.*;
import java.util.ArrayList;
@@ -20,7 +18,7 @@ import java.util.List;
/**
* Created by ModdyLP on 01.07.2017. Website: https://moddylp.de/
*/
public class Permission extends Module implements LanguageInterface {
public class Permission extends Module implements Fast {

@Command(
command = "addperm",
@@ -148,7 +146,7 @@ public class Permission extends Module implements LanguageInterface {
}
}
for (EmbedBuilder builderinst: builders) {
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builderinst);
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builderinst, false);
}
} else {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.getTranslation("norolefound")), true);
@@ -167,6 +165,9 @@ public class Permission extends Module implements LanguageInterface {
return Utils.makeArgsToString(args, new String[]{}).equalsIgnoreCase("everyone");
}

@LanguageMethod(
languagestringcount = 6
)
@Override
public void setdefaultLanguage() {
//Permission

+ 70
- 47
src/main/java/modules/RoleManagement.java View File

@@ -5,16 +5,12 @@ import events.Command;
import events.Module;
import org.json.JSONArray;
import org.json.JSONObject;
import storage.LanguageInterface;
import sx.blah.discord.api.events.EventSubscriber;
import storage.LanguageMethod;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IGuild;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.IUser;
import util.Console;
import util.Globals;
import util.SMB;
import util.Utils;
import util.*;

import java.util.ArrayList;
import java.util.Arrays;
@@ -25,10 +21,11 @@ import java.util.List;
* Created by N.Hartmann on 06.07.2017.
* Copyright 2017
*/
public class RoleManagement extends Module implements LanguageInterface{
public class RoleManagement extends Module implements Fast {

public static String female = "f";
public static String male = "m";
private static String GENDER = "gender.json";

private static HashMap<String, HashMap<IGuild, List<IRole>>> gendersave = new HashMap<>();

@@ -90,12 +87,17 @@ public class RoleManagement extends Module implements LanguageInterface{
try {
HashMap<IGuild, List<IRole>> roletoserver = new HashMap<>();
List<IRole> roles = event.getGuild().getRolesByName(Utils.makeArgsToString(args, new String[]{args[0]}));
if (args[0].equalsIgnoreCase(female) || (args[0].equalsIgnoreCase(male))) {
roletoserver.put(event.getGuild(), roles);
gendersave.put(args[0], roletoserver);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("role_gender_add"), roles.size(), args[0])), true);
if (roles.size() > 0) {
if (args[0].equalsIgnoreCase(female) || (args[0].equalsIgnoreCase(male))) {
roletoserver.put(event.getGuild(), roles);
gendersave.put(args[0], roletoserver);
saveGenders();
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("role_gender_add"), roles.size(), args[0])), true);
} else {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.getTranslation("role_gender_notfound")), true);
}
} else {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.getTranslation("role_gender_notfound")), true);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.getTranslation("role_notfound")), true);
}
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), Arrays.toString(ex.getStackTrace()))), true);
@@ -108,37 +110,54 @@ public class RoleManagement extends Module implements LanguageInterface{
}

public static List<IRole> getRoleforGender(IGuild guild, String gender) {
return gendersave.get(gender).get(guild);
if (guild == null) {
Console.error("Guild is null");
} else {
return gendersave.get(gender).get(guild);
}
return null;
}

public static void saveGenders() {
try {
Console.println("Saving Roles for RoleManagement");
if (DRIVER.getPropertyOnly(DRIVER.CONFIG, "genderroles").equals(true)) {
JSONObject root = new JSONObject();
ArrayList<JSONObject> maleserverids = new ArrayList<>();
ArrayList<JSONObject> femaleserverids = new ArrayList<>();
if (gendersave.get(female) != null) {
gendersave.get(female).keySet().forEach(iGuild -> {
JSONObject root = new JSONObject();
ArrayList<JSONObject> maleserverids = new ArrayList<>();
ArrayList<JSONObject> femaleserverids = new ArrayList<>();
if (gendersave.get(female) != null) {
gendersave.get(female).keySet().forEach(iGuild -> {
if (!SERVER_CONTROL.getDisabledlist(SERVER_CONTROL.JOIN_MODULE).contains(iGuild.getStringID())) {
ArrayList<String> roleids = new ArrayList<>();
for (IRole role: getRoleforGender(iGuild, female)) {
roleids.add(role.getStringID());
}
JSONObject femaleobj = new JSONObject();
femaleobj.append(iGuild.getStringID(), getRoleforGender(iGuild, female));
femaleobj.put(iGuild.getStringID(), roleids);
femaleserverids.add(femaleobj);
});
}
if (gendersave.get(male) != null) {
gendersave.get(male).keySet().forEach(iGuild -> {
} else {
Console.debug("Server is disabled for using Genders: "+iGuild.getName()+ Arrays.toString(SERVER_CONTROL.getDisabledlist(SERVER_CONTROL.JOIN_MODULE).toArray()));
}
});
}
if (gendersave.get(male) != null) {
gendersave.get(male).keySet().forEach(iGuild -> {
if (!SERVER_CONTROL.getDisabledlist(SERVER_CONTROL.JOIN_MODULE).contains(iGuild.getStringID())) {
ArrayList<String> roleids = new ArrayList<>();
for (IRole role: getRoleforGender(iGuild, male)) {
roleids.add(role.getStringID());
}
JSONObject femaleobj = new JSONObject();
femaleobj.append(iGuild.getStringID(), getRoleforGender(iGuild, male));
femaleobj.put(iGuild.getStringID(), roleids);
maleserverids.add(femaleobj);
});
}
root.append(female, femaleserverids);
root.append(male, maleserverids);
DRIVER.setProperty(DRIVER.CONFIG, "gendersave", root);
DRIVER.saveJson();
} else {
Console.error("Gender Module disabled");
} else {
Console.debug("Server is disabled for using Genders: "+iGuild.getName()+ Arrays.toString(SERVER_CONTROL.getDisabledlist(SERVER_CONTROL.JOIN_MODULE).toArray()));
}
});
}
root.put(female, femaleserverids);
root.put(male, maleserverids);
DRIVER.setProperty(GENDER, "gendersave", root);
DRIVER.saveJson();
} catch (Exception ex) {
ex.printStackTrace();
}
@@ -147,10 +166,9 @@ public class RoleManagement extends Module implements LanguageInterface{
public static void loadGenders() {
try {
Console.println("Loading Roles for RoleManagement");
if (DRIVER.getPropertyOnly(DRIVER.CONFIG, "genderroles").equals(true)) {
ArrayList<JSONObject> maleserverids = new ArrayList<>();
ArrayList<JSONObject> femaleserverids = new ArrayList<>();
JSONObject root = Utils.objectToJSONObject(DRIVER.getProperty(DRIVER.CONFIG, "gendersave", new JSONObject()));
DRIVER.createNewFile(GENDER);
JSONObject root = Utils.objectToJSONObject(DRIVER.getProperty(GENDER, "gendersave", new JSONObject()));
if (root.keySet().contains(male) && root.keySet().contains(female)) {
Console.debug(Utils.crunchifyPrettyJSONUtility(root.toString(4)));
JSONArray malelist = root.getJSONArray(male);
JSONArray femalelist = root.getJSONArray(female);
@@ -160,8 +178,6 @@ public class RoleManagement extends Module implements LanguageInterface{
if (female != null) {
putvaluesfromlist(female, femalelist);
}
} else {
Console.error("Gender Module disabled");
}
} catch (Exception ex) {
ex.printStackTrace();
@@ -173,13 +189,15 @@ public class RoleManagement extends Module implements LanguageInterface{
HashMap<IGuild, List<IRole>> serverrolesmap = new HashMap<>();
for (int i = 0; i < list.length(); i++) {
JSONObject serverroles = Utils.objectToJSONObject(list.get(i));
for (Object serverid : serverroles.keySet()) {
JSONArray array = Utils.objectToJSONArray(serverroles.get(serverid.toString()));
ArrayList<IRole> roles = new ArrayList<>();
for (int j = 0; j < array.length(); j++) {
roles.add(INIT.BOT.getRoleByID(Long.valueOf(array.getString(i))));
if (serverroles != null) {
for (Object serverid : serverroles.keySet()) {
JSONArray array = Utils.objectToJSONArray(serverroles.get(serverid.toString()));
ArrayList<IRole> roles = new ArrayList<>();
for (int j = 0; j < array.length(); j++) {
roles.add(INIT.BOT.getRoleByID(Long.valueOf(array.getString(i))));
}
serverrolesmap.put(INIT.BOT.getGuildByID(Long.valueOf(serverid.toString())), roles);
}
serverrolesmap.put(INIT.BOT.getGuildByID(Long.valueOf(serverid.toString())), roles);
}

}
@@ -187,6 +205,9 @@ public class RoleManagement extends Module implements LanguageInterface{
}
}

@LanguageMethod(
languagestringcount = 8
)
@Override
public void setdefaultLanguage() {
//Role Manager
@@ -194,7 +215,9 @@ public class RoleManagement extends Module implements LanguageInterface{
DRIVER.setProperty(DEF_LANG, "role_remove", "Role %1s removed successful to User %2s");
DRIVER.setProperty(DEF_LANG, "role_gender_add", "Role %1s was added as Gender %2s");
DRIVER.setProperty(DEF_LANG, "role_gender_notfound", "This Gender is not defined.");
DRIVER.setProperty(DEF_LANG, "female_ask", "Are you Male or Female? Answer with the Gender like this: @Botname w ");
DRIVER.setProperty(DEF_LANG, "gender_role_added", "You get the Role specified for your Gender.");
DRIVER.setProperty(DEF_LANG, "female_ask", "Are you Male or Female? \nAnswer with the Gender like this: \n@%1s f or @%1s m \n f = female, w = male");
DRIVER.setProperty(DEF_LANG, "gender_role_added", "You get the Role: %1s");
DRIVER.setProperty(DEF_LANG, "role_notfound", "The Role was not found.");
DRIVER.setProperty(DEF_LANG, "invalid_count_gender", "Your answer is not well formated. \n Look again on the Question.");
}
}

+ 6
- 5
src/main/java/modules/SearchCommand.java View File

@@ -4,16 +4,14 @@ import discord.BotUtils;
import events.Command;
import events.Module;
import storage.LanguageInterface;
import util.Globals;
import storage.LanguageMethod;
import util.*;
import org.json.JSONArray;
import org.json.JSONObject;
import storage.RestRequest;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IGuild;
import sx.blah.discord.util.EmbedBuilder;
import util.Console;
import util.SMB;
import util.Utils;

import java.awt.*;
import java.util.ArrayList;
@@ -22,7 +20,7 @@ import java.util.HashMap;
/**
* Created by ModdyLP on 29.06.2017. Website: https://moddylp.de/
*/
public class SearchCommand extends Module implements LanguageInterface{
public class SearchCommand extends Module implements Fast{

private HashMap<IGuild, ArrayList<String>> links = new HashMap<>();
private HashMap<IGuild, Integer> searchmarker = new HashMap<>();
@@ -151,6 +149,9 @@ public class SearchCommand extends Module implements LanguageInterface{
BotUtils.sendEmbMessage(event.getChannel(), builder, false);
}

@LanguageMethod(
languagestringcount = 9
)
@Override
public void setdefaultLanguage() {
//Search

+ 66
- 5
src/main/java/modules/ServerManager.java View File

@@ -2,27 +2,56 @@ package modules;

import discord.BotUtils;
import events.Command;
import events.Module;
import storage.LanguageInterface;
import storage.LanguageMethod;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IGuild;
import sx.blah.discord.util.EmbedBuilder;
import util.Fast;
import util.Globals;
import util.Markdown;
import util.SMB;

import java.awt.*;
import java.util.List;

/**
* Created by N.Hartmann on 07.07.2017.
* Copyright 2017
*/
public class ServerManager implements Fast{
public class ServerManager extends Module implements Fast{
@Command(
command = "setserverenabled",
alias = "sse",
description = "Removes a Server from List",
arguments = {"ServerID", "Module"},
permission = Globals.BOT_OWNER,
prefix = Globals.MUSIC_PREFIX
arguments = {"ServerID", "Module {join, music, banned}"},
permission = Globals.BOT_MANAGE,
prefix = Globals.ADMIN_PREFIX
)
public boolean removeDisabledServer(MessageReceivedEvent event, String[] args) {
try {
SERVER_CONTROL.removeDisabledServer(INIT.BOT.getGuildByID(Long.valueOf(args[0])), SERVER_CONTROL.MUSIC_MODULE);
SERVER_CONTROL.removeDisabledServer(INIT.BOT.getGuildByID(Long.valueOf(args[0])), args[1]);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("command_success")), true);
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), ex.getMessage())), true);
ex.printStackTrace();
}
return true;
}

@Command(
command = "banserver",
alias = "bans",
description = "Ban a Server",
arguments = {"ServerID"},
permission = Globals.BOT_MANAGE,
prefix = Globals.ADMIN_PREFIX
)
public boolean banServer(MessageReceivedEvent event, String[] args) {
try {
SERVER_CONTROL.addBannedServer(args[0]);
DRIVER.saveJson();
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("command_success")), true);
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), ex.getMessage())), true);
@@ -30,4 +59,36 @@ public class ServerManager implements Fast{
}
return true;
}
@Command(
command = "getserver",
arguments = {},
description = "Get Servers",
alias = "gets",
permission = Globals.BOT_OWNER,
prefix = Globals.ADMIN_PREFIX
)
public boolean getServer(MessageReceivedEvent event, String[] args) {
try {
List<IGuild> server = INIT.BOT.getGuilds();
EmbedBuilder builder = new EmbedBuilder();
builder.withTitle("ServerList");
builder.withDescription(Markdown.bold("Size: "+server.size())+" \n");
for (IGuild serverinst: server) {
builder.appendDesc(Markdown.bold(serverinst.getName())+": "+serverinst.getStringID()+" \n");
}
builder.withColor(Color.green);
BotUtils.sendPrivEmbMessage(event.getAuthor().getOrCreatePMChannel(), builder, false);
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.SUCCESS+LANG.getTranslation("commonmessage_error"), ex.getMessage())), true);
}
return true;
}

@LanguageMethod(
languagestringcount = 0
)
@Override
public void setdefaultLanguage() {
super.setdefaultLanguage();
}
}

+ 6
- 1
src/main/java/modules/music/MainMusic.java View File

@@ -12,11 +12,13 @@ import events.Command;
import events.Module;
import events.UserEvents;
import storage.LanguageInterface;
import storage.LanguageMethod;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IGuild;
import sx.blah.discord.handle.obj.IVoiceChannel;
import sx.blah.discord.util.audio.AudioPlayer;
import util.Fast;
import util.Globals;
import util.SMB;

@@ -26,7 +28,7 @@ import java.util.Map;
/**
* Created by ModdyLP on 30.06.2017. Website: https://moddylp.de/
*/
public class MainMusic extends Module implements LanguageInterface{
public class MainMusic extends Module implements Fast{

public static final AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
private static final Map<Long, GuildMusicManager> musicManagers = new HashMap<>();
@@ -193,6 +195,9 @@ public class MainMusic extends Module implements LanguageInterface{
BotUtils.sendEmbMessage(channel, SMB.shortMessage(LANG.getTranslation("music_skip")), true);
}

@LanguageMethod(
languagestringcount = 10
)
@Override
public void setdefaultLanguage() {
//Music

+ 2
- 2
src/main/java/storage/FileDriver.java View File

@@ -101,7 +101,7 @@ public class FileDriver {
*/
public void loadJson() {
try {
//Console.println("LOADJSON");
//Console.println("===LOADFILE===");
for (String filename: files.keySet()) {
BufferedReader reader = new BufferedReader(new FileReader(files.get(filename)));
StringBuilder content = new StringBuilder();
@@ -125,7 +125,7 @@ public class FileDriver {
*/
public void saveJson() {
try {
//Console.println("SAVEJSON");
//Console.println("===SAVEFILE===");
for (String filename: files.keySet()) {
BufferedWriter writer = new BufferedWriter(new FileWriter(files.get(filename)));
String json = jsons.get(filename).toString();

+ 0
- 76
src/main/java/storage/LanguageLoader.java View File

@@ -83,82 +83,6 @@ public class LanguageLoader implements Fast{
DRIVER.setProperty(DEF_LANG, "command_success_wait", "The command was successful. Please wait... Result is generating...");
DRIVER.setProperty(DEF_LANG, "shutdowninfo", "The Bot will shutting down in 10 seconds! Bye bye.");

<<<<<<< Updated upstream
//Stats Command
DRIVER.setProperty(DEF_LANG, "stats_title", "General Stats");
DRIVER.setProperty(DEF_LANG, "stats_servercount", "Server Count");
DRIVER.setProperty(DEF_LANG, "stats_shards", "Shards");
DRIVER.setProperty(DEF_LANG, "stats_shard_ping", "Ping for Shard");
DRIVER.setProperty(DEF_LANG, "stats_ram", "Ram Usage");
DRIVER.setProperty(DEF_LANG, "stats_owner", "Bot Owner");
DRIVER.setProperty(DEF_LANG, "stats_user", "Users");
DRIVER.setProperty(DEF_LANG, "stats_commands", "Commands");
DRIVER.setProperty(DEF_LANG, "stats_uptime", "Uptime");

//Help Command
DRIVER.setProperty(DEF_LANG, "help_title", "All Commands");
DRIVER.setProperty(DEF_LANG, "help_command", "Command");
DRIVER.setProperty(DEF_LANG, "help_alias", "Alias");
DRIVER.setProperty(DEF_LANG, "help_arguments", "Arguments");
DRIVER.setProperty(DEF_LANG, "help_description", "Description");
DRIVER.setProperty(DEF_LANG, "help_noneinfo", "If you want to reset a Value, then type for each argument NA.");
DRIVER.setProperty(DEF_LANG, "help_prefixinfo", "\nThe Prefixes are \n" +
"Admin Prefix: ! \n" +
"Info Prefix: . \n" +
"Game Prefix: ~ \n" +
"music Prefix: $ \n");
DRIVER.setProperty(DEF_LANG, "help_permission", "Permission");

//Deletion
DRIVER.setProperty(DEF_LANG, "del_topic", "Deletion %1s of %2s");

//Search
DRIVER.setProperty(DEF_LANG, "engine_unknown", "The Search Engine is unknown!");
DRIVER.setProperty(DEF_LANG, "results_end", "You reached the end of results.");
DRIVER.setProperty(DEF_LANG, "results_cleared", "The results were cleared.");
DRIVER.setProperty(DEF_LANG, "searchtoken_google", "Please provide a google search api token.");
DRIVER.setProperty(DEF_LANG, "result_out", "The Result is out of Range.");
DRIVER.setProperty(DEF_LANG, "no_search", "There is no search running.");
DRIVER.setProperty(DEF_LANG, "search_result", "Your search Result");
DRIVER.setProperty(DEF_LANG, "search_info", "Search Query");
DRIVER.setProperty(DEF_LANG, "search_count", "Result %1s of %2s");

//Music
DRIVER.setProperty(DEF_LANG, "music_notinchannel", "The Bot is not in a voice Channel.");
DRIVER.setProperty(DEF_LANG, "music_notinchannel_user", "You are not in a Voice Channel.");
DRIVER.setProperty(DEF_LANG, "music_volumechange", "Volume changed from %1s to %2s.");
DRIVER.setProperty(DEF_LANG, "music_volumechangeerror", "Can't change volume.");
DRIVER.setProperty(DEF_LANG, "music_add","Adding to queue: %1s.");
DRIVER.setProperty(DEF_LANG, "music_add_queue", "Adding to queue %1s (first track of playlist %2s).");
DRIVER.setProperty(DEF_LANG, "music_notfound", "Nothing found by %1s.");
DRIVER.setProperty(DEF_LANG, "music_notloaded", "Could not play the choosen song.");
DRIVER.setProperty(DEF_LANG, "music_skip", "Skipped to next track.");
DRIVER.setProperty(DEF_LANG, "disabledserver", "This server is disabled for using the Music Module");

//Changes
DRIVER.setProperty(DEF_LANG, "changeprop_error", "This option can't found in the config file!");
DRIVER.setProperty(DEF_LANG, "notchanged_error", "The change Command does not provide resetting.");
DRIVER.setProperty(DEF_LANG, "parse_error", "The Value cant parsed into a valid format.");
DRIVER.setProperty(DEF_LANG, "props", "Properties");

//Permission
DRIVER.setProperty(DEF_LANG, "perm_add_success", "Permission added successful.");
DRIVER.setProperty(DEF_LANG, "perm_add_failed", "Failed to add Permission to group.");
DRIVER.setProperty(DEF_LANG, "perm_rem_success", "Permission removed successful.");
DRIVER.setProperty(DEF_LANG, "perm_rem_failed", "Failed to remove Permission to group.");
DRIVER.setProperty(DEF_LANG, "permlist_title", "Permission List for Group %1s");
DRIVER.setProperty(DEF_LANG, "norolefound", "The Role was not found.");

//Role Manager
DRIVER.setProperty(DEF_LANG, "role_add", "Role %1s added successful to User %2s");
DRIVER.setProperty(DEF_LANG, "role_remove", "Role %1s removed successful to User %2s");
DRIVER.setProperty(DEF_LANG, "role_gender_add", "Role %1s was added as Gender %2s");
DRIVER.setProperty(DEF_LANG, "role_gender_notfound", "This Gender is not defined.");
DRIVER.setProperty(DEF_LANG, "female_ask", "Are you Male or Female? Answer with the Gender like this: @Botname w ");
DRIVER.setProperty(DEF_LANG, "gender_role_added", "You get the Role specified for your Gender.");

=======
>>>>>>> Stashed changes
DRIVER.saveJson();
}


+ 13
- 0
src/main/java/storage/LanguageMethod.java View File

@@ -0,0 +1,13 @@
package storage;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
* Created by N.Hartmann on 07.07.2017.
* Copyright 2017
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface LanguageMethod {
int languagestringcount();
}

+ 15
- 6
src/main/java/util/Console.java View File

@@ -24,8 +24,11 @@ public class Console implements Fast{
public static void debug(String message) {
if (DRIVER.getPropertyOnly(DRIVER.CONFIG,"debug").equals(true)) {
String debugprefix = "[DEBUG]";
System.out.println(Utils.format(getTimeNow())+prefix + debugprefix + message);
logger.info(prefix + debugprefix + message);
String[] parts = message.split("\n");
for (String part: parts) {
System.out.println(Utils.format(getTimeNow())+prefix + debugprefix + part);
logger.info(prefix + debugprefix + part);
}
}

}
@@ -36,8 +39,11 @@ public class Console implements Fast{
*/
public static void error(String message) {
String errorprefix = "[ERROR]";
System.out.println(Utils.format(getTimeNow())+prefix + errorprefix + message);
logger.error(prefix + errorprefix + message);
String[] parts = message.split("\n");
for (String part: parts) {
System.out.println(Utils.format(getTimeNow())+prefix + errorprefix + part);
logger.info(prefix + errorprefix + part);
}
}

/**
@@ -46,8 +52,11 @@ public class Console implements Fast{
*/
public static void println(String message) {
String infoprefix = "[INFO]";
System.out.println(Utils.format(getTimeNow())+prefix + infoprefix + message);
logger.info(prefix + infoprefix + message);
String[] parts = message.split("\n");
for (String part: parts) {
System.out.println(Utils.format(getTimeNow())+prefix + infoprefix + part);
logger.info(prefix + infoprefix + part);
}
}

private static Date getTimeNow() {

+ 10
- 5
src/main/java/util/GetAnnotation.java View File

@@ -1,7 +1,10 @@
package util;

import events.Command;
import events.Module;
import events.RegisterCommands;
import storage.LanguageInterface;
import storage.LanguageMethod;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;

import java.lang.reflect.Method;
@@ -18,17 +21,14 @@ public class GetAnnotation implements Fast{
* @param clazz Class
* @return A Collection of Annotation and Methods
*/
public static HashMap<Command, Method> getCommandAnnotation(Class clazz){
public static HashMap<Command, Method> getCommandAnnotation(Class clazz, Module instance){
HashMap<Command, Method> allannotation = new HashMap<>();
Console.debug("----------------Module: "+clazz.getName()+"----------------");
try {
Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods) {
if(method.getName().equals("setdefaultLanguage")) {
Console.debug("Load Language: "+method.getName());
method.invoke(method);
}
Command annotation = method.getAnnotation(Command.class);
LanguageMethod language = method.getAnnotation(LanguageMethod.class);
if (annotation != null) {
if (method.getParameters().length == 2) {
if (method.getParameters()[0].getParameterizedType().equals(MessageReceivedEvent.class) && method.getParameters()[1].getParameterizedType().equals(String[].class)) {
@@ -41,10 +41,15 @@ public class GetAnnotation implements Fast{
} else {
Console.error("Method has no valid Parameters Count: "+method.getName());
}
} else if (language != null) {
Console.debug("Language: " + language.languagestringcount()+" in "+method.getName()+" "+clazz.getName()+" "+instance.getClass().getName());
COMMAND.languages.put(language, method);
COMMAND.langinstances.put(language, instance);
}
}
} catch (Exception ex) {
Console.error(String.format(LANG.getTranslation("annotation_error"), clazz.getName(), ex.getMessage()));
ex.printStackTrace();
}
return allannotation;
}

+ 9
- 1
src/main/java/util/SMB.java View File

@@ -9,8 +9,16 @@ import java.awt.*;
*/
public class SMB {
public static EmbedBuilder shortMessage(String message) {
String[] messageparts = message.split("\n");
EmbedBuilder builder = new EmbedBuilder();
builder.withTitle(message);
if (messageparts.length > 1) {
builder.withTitle(messageparts[0]);
for (int i = 1; i < messageparts.length; i++) {
builder.appendDesc(messageparts[i]+"\n");
}
} else {
builder.withTitle(message);
}
builder.withColor(Color.green);
return builder;
}

+ 1
- 1
src/main/java/util/Utils.java View File

@@ -51,7 +51,7 @@ public class Utils {
public static String makeArgsToString(String[] args, String[] replace) {
String string = Arrays.toString(args).replace("[", "").replace("]", "").replace(",", "");
for (String arg: replace) {
string = string.replace(arg, "");
string = string.replaceFirst(arg, "");
}
return string.trim();
}

Loading…
Cancel
Save