Browse Source

Merge pull request #11 from ModdyLP/develop_moddylp

Develop moddylp
master
Niklas H. 2 years ago
committed by GitHub
parent
commit
ca66aaa432
24 changed files with 223 additions and 124 deletions
  1. +1
    -1
      README.md
  2. +6
    -0
      lang/lang_en.json
  3. +0
    -1
      momuosb.iml
  4. +10
    -9
      src/main/java/discord/ServerControl.java
  5. +8
    -2
      src/main/java/discord/Stats.java
  6. +5
    -4
      src/main/java/events/EventListener.java
  7. +1
    -1
      src/main/java/events/Module.java
  8. +1
    -1
      src/main/java/events/RegisterCommands.java
  9. +3
    -1
      src/main/java/events/ServerListener.java
  10. +1
    -1
      src/main/java/events/UserEvents.java
  11. +1
    -1
      src/main/java/main/MoMuOSBMain.java
  12. +10
    -7
      src/main/java/modules/Gamestats.java
  13. +85
    -14
      src/main/java/modules/InfoCommands.java
  14. +35
    -34
      src/main/java/modules/Moderation.java
  15. +3
    -3
      src/main/java/modules/Permission.java
  16. +8
    -16
      src/main/java/modules/RoleManagement.java
  17. +1
    -1
      src/main/java/modules/SearchCommand.java
  18. +3
    -6
      src/main/java/modules/ServerManager.java
  19. +2
    -2
      src/main/java/permission/PermissionController.java
  20. +9
    -9
      src/main/java/storage/FileDriver.java
  21. +1
    -1
      src/main/java/storage/WebClient.java
  22. +12
    -1
      src/main/java/util/Console.java
  23. +1
    -1
      src/main/java/util/GetAnnotation.java
  24. +16
    -7
      src/main/resources/log4j.properties

+ 1
- 1
README.md View File

@@ -1,5 +1,5 @@
# MoMuOSB
### Multi OS Discord Bot
### Multi OS Discord Bot [![Build Status](https://ci.moddylp.de/job/MoMuOSB/badge/icon)](https://ci.moddylp.de/job/MoMuOSB/)
***
Build with Maven



+ 6
- 0
lang/lang_en.json View File

@@ -46,6 +46,7 @@
"shutdowninfo": "The Bot will shutting down in 10 seconds! Bye bye.",
"getServer_getserver": "Get Servers",
"search_result": "Your search Result",
"game_overwatch_level": "Level",
"playMusic_play": "The Bot plays the first song.",
"stats_uptime": "Uptime",
"setplaying_setplaying": "Change the Bot Game",
@@ -67,6 +68,7 @@
"skipTrack_skip": "The Bot skips a song.",
"perm_rem_success": "Permission removed successful.",
"del_topic": "Deletion %1s of %2s",
"help_page": "Page",
"changeStatus_changestatus": "Change the Status",
"music_volumechange": "Volume changed from %1s to %2s.",
"perm_add_success": "Permission added successful.",
@@ -76,12 +78,15 @@
"printProperties_printprop": "Print the Property",
"role_notfound": "The Role was not found.",
"getGameStats_gamestats": "Get Statistics about a Player in a Game",
"game_unsupported": "This Game isn\u0027t supported.",
"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!",
"del_wait_success": "Deletion invoked... Wait until messages disapear.",
"deleteMessages_deletemessages": "Deletion of Message Amount",
"addPermToGroup_addperm": "Add Permission to Group",
"game_overwatch_comprank": "Competitive Rank",
"leaveMusic_leave": "The Bot leaves voice Server",
"searchtoken_google": "Please provide a google search api token.",
"music_add": "Adding to queue: %1s.",
@@ -92,6 +97,7 @@
"help_command": "Command",
"changeProperty_changeprop": "Change the Property",
"music_add_queue": "Adding to queue %1s (first track of playlist %2s).",
"game_overwatch_gameswon": "Games Won Quickplay",
"music_notloaded": "Could not play the choosen song.",
"music_skip": "Skipped to next track.",
"deleteprivateMessages_deleteprivmsg": "Shutdown the bot",


+ 0
- 1
momuosb.iml View File

@@ -10,7 +10,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
<orderEntry type="library" name="Maven: com.github.austinv11:Discord4J:2.8.4" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.24" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.6" level="project" />


+ 10
- 9
src/main/java/discord/ServerControl.java View File

@@ -37,32 +37,32 @@ public class ServerControl implements Fast{
try {
if (disabledlist.get(module) != null && !disabledlist.get(module).contains(guild.getStringID())) {
if (newserver) {
Console.debug("Server added as New");
Console.debug(module+"| 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");
Console.debug(module+"| Server exists");
disabledlist.get(module).add(guild.getStringID());
DRIVER.getProperty(DRIVER.CONFIG, module+"_disabled_servers", disabledlist.get(module));
}
Console.debug("Saved: |"+guild.getStringID()+" "+module+" "+guild.getStringID());
}
} catch (Exception ex) {
Console.error("Cant add Server");
ex.printStackTrace();
Console.error(module+"| Cant add Server");
Console.error(ex);
}
}
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");
Console.debug("Server added as Banned");
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();
Console.error("Banned| Cant add Server");
Console.error(ex);
}
}
public void loadSavedServer(String module) {
@@ -76,6 +76,7 @@ public class ServerControl implements Fast{
}
}
}
Console.debug("Disabled Servers: "+module+" |"+ disabledlist.get(module).size());
}
public void removeDisabledServer(IGuild guild, String module) {
try {
@@ -86,7 +87,7 @@ public class ServerControl implements Fast{
}
} catch (Exception ex) {
Console.error("Cant remove Server");
ex.printStackTrace();
Console.error(ex);
}
}
public boolean checkServerisBanned(IGuild guild) {
@@ -99,7 +100,7 @@ public class ServerControl implements Fast{
return false;
}
public ArrayList<String> getDisabledlist(String module) {
Console.debug(disabledlist.get(JOIN_MODULE).size()+" "+disabledlist.get(MUSIC_MODULE).size());
return disabledlist.get(module);
}
}

+ 8
- 2
src/main/java/discord/Stats.java View File

@@ -4,6 +4,7 @@ import org.json.JSONArray;
import sx.blah.discord.handle.obj.IGuild;
import util.Console;
import util.Fast;
import util.SMB;
import util.Utils;

import java.util.ArrayList;
@@ -29,6 +30,11 @@ public class Stats implements Fast {
if (!serverlist.contains(server.getStringID())) {
joinedserver = joinedserver + 1;
serverlist.add(server.getStringID());
BotUtils.sendPrivEmbMessage(server.getOwner().getOrCreatePMChannel(), SMB.shortMessage("Hello, \n" +
"I'm your new Discord bot. \n" +
"Type "+DRIVER.getPropertyOnly(DRIVER.CONFIG, "botprefix").toString()+".help \n" +
"If you have any Problems then contact me (https://moddylp.de/). \n \n" +
"Have a nice Day"), false);
}
}

@@ -59,7 +65,7 @@ public class Stats implements Fast {
DRIVER.saveJson();
Console.println(getStats());
} catch (Exception ex) {
ex.printStackTrace();
Console.error(ex);
}
}

@@ -79,7 +85,7 @@ public class Stats implements Fast {
commands = Integer.valueOf(DRIVER.getProperty(STATS, "commands", commands).toString());
Console.println(getStats());
}catch (Exception ex) {
ex.printStackTrace();
Console.error(ex);
}
}



+ 5
- 4
src/main/java/events/EventListener.java View File

@@ -52,7 +52,8 @@ public class EventListener implements Fast {
Stats.addMessages();
if (SERVER_CONTROL.checkServerisBanned(event.getGuild())) {
Console.println("Leave Banned Server: "+event.getGuild().getName());
//event.getGuild().leave();
BotUtils.sendPrivMessage(event.getGuild().getOwner().getOrCreatePMChannel(), "Your Server is on the banned Server List. Please contact webmaster@moddylp.de and describe why do you want to get unbanned.", false);
event.getGuild().leave();
}
//Check if Channel is Private (DM)
//Console.debug("MI: "+event.getGuild().getStringID()+" "+event.getChannel().getName()+" "+event.getAuthor().getName());
@@ -72,7 +73,6 @@ 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")), true);
}
}
if (PERM.hasPermission(event.getAuthor(), event.getGuild(), command.permission())) {
@@ -95,8 +95,9 @@ public class EventListener implements Fast {
}
}
} catch (Exception ex) {
BotUtils.sendMessage(event.getChannel(), String.format(LANG.getTranslation("commonmessage_error"), "Execution failed"), true);
Console.error(String.format(LANG.getTranslation("commonmessage_error"), Arrays.toString(ex.getStackTrace())));
ex.printStackTrace();
Console.error(ex);
}
}).start();
}
@@ -147,7 +148,7 @@ public class EventListener implements Fast {

} catch (Exception ex) {
Console.error(String.format(LANG.getTranslation("execution_error"), ex.getCause()));
ex.printStackTrace();
Console.error(ex);
}
}



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

@@ -11,6 +11,6 @@ import util.Fast;
public class Module implements Fast, LanguageInterface {
@Override
public void setdefaultLanguage() {
Console.error("No Language");
Console.println("No Language for "+this.getClass().getName());
}
}

+ 1
- 1
src/main/java/events/RegisterCommands.java View File

@@ -33,7 +33,7 @@ public class RegisterCommands implements Fast{
COMMAND.langinstances.get(language).setdefaultLanguage();
}
}catch (Exception ex) {
ex.printStackTrace();
Console.error(ex);
System.exit(0);
}
DRIVER.saveJson();


+ 3
- 1
src/main/java/events/ServerListener.java View File

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

import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import discord.BotUtils;
import discord.Stats;
import discord.SystemInfo;
import modules.RoleManagement;
@@ -99,7 +100,8 @@ public class ServerListener implements Fast{
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();
BotUtils.sendPrivMessage(event.getGuild().getOwner().getOrCreatePMChannel(), "Your Server is on the banned Server List. Please contact webmaster@moddylp.de and describe why do you want to get unbanned.", false);
event.getGuild().leave();
} else {
if (running) {
Stats.addServer(event.getGuild());


+ 1
- 1
src/main/java/events/UserEvents.java View File

@@ -39,7 +39,7 @@ public class UserEvents implements Fast{

@EventSubscriber
public void onUserJoin(UserJoinEvent event) {
Console.debug(Console.recievedprefix+"User joined: "+event.getUser().getName()+" to Server: "+event.getGuild().getName());
Console.debug(Console.recievedprefix+"User joined: [S]"+event.getGuild().getName()+" [U]"+event.getUser().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())) {


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

@@ -42,7 +42,7 @@ public class MoMuOSBMain implements Fast {

} catch (Exception ex) {
Console.error(ex.getMessage());
ex.printStackTrace();
Console.error(ex);
}

}


+ 10
- 7
src/main/java/modules/Gamestats.java View File

@@ -42,24 +42,27 @@ public class Gamestats extends Module implements Fast{
JSONObject competitive = stats.getJSONObject("competitive").getJSONObject("overall_stats");
JSONObject quickplay = stats.getJSONObject("quickplay").getJSONObject("game_stats");
builder.withThumbnail(competitive.getString("avatar"));
builder.withTitle(args[1]+" Level: "+(competitive.getInt("prestige") * 100 + competitive.getInt("level")));
builder.appendField("Competitive Rank", competitive.get("comprank").toString()+" "+competitive.getString("tier"), false);
builder.appendField("Games Won Quickplay", quickplay.get("games_won").toString(), false);
builder.withTitle(args[1]+" "+LANG.getTranslation("game_overwatch_level")+": "+(competitive.getInt("prestige") * 100 + competitive.getInt("level")));
builder.appendField(LANG.getTranslation("game_overwatch_comprank")+": ", competitive.get("comprank").toString()+" "+competitive.getString("tier"), false);
builder.appendField(LANG.getTranslation("game_overwatch_gameswon"), quickplay.get("games_won").toString(), false);
BotUtils.sendEmbMessage(event.getChannel(), builder, false);
} else {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage("This Game isn't supported."), true);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.getTranslation("game_unsupported")), true);
}
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), ex.getMessage())), true);
ex.printStackTrace();
Console.error(ex);
}
}

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

DRIVER.setProperty(DEF_LANG, "game_overwatch_level", "Level");
DRIVER.setProperty(DEF_LANG, "game_overwatch_comprank", "Competitive Rank");
DRIVER.setProperty(DEF_LANG, "game_overwatch_gameswon", "Games Won Quickplay");
DRIVER.setProperty(DEF_LANG, "game_unsupported", "This Game isn't supported.");
}
}

+ 85
- 14
src/main/java/modules/InfoCommands.java View File

@@ -5,19 +5,18 @@ import discord.DiscordInit;
import discord.SystemInfo;
import events.Command;
import events.Module;
import storage.LanguageInterface;
import storage.LanguageMethod;
import sx.blah.discord.handle.obj.*;
import util.*;
import main.MoMuOSBMain;
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.handle.obj.Permissions;
import sx.blah.discord.handle.obj.StatusType;
import sx.blah.discord.util.BotInviteBuilder;
import sx.blah.discord.util.EmbedBuilder;

import java.awt.*;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
@@ -53,6 +52,37 @@ public class InfoCommands extends Module implements Fast {
return true;
}

/**
* Help Command
*
* @param event MessageEvent
* @param args Argumente [Not needed]
* @return state
*/
@Command(
command = "getregister",
description = "Display the help",
alias = "greg",
arguments = {"Mention User []"},
permission = Globals.BOT_INFO,
prefix = Globals.INFO_PREFIX
)
public boolean getRegisterDate(MessageReceivedEvent event, String[] args) {
new Thread(() -> {
StringBuilder content = new StringBuilder();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy H:m:s");
if (event.getMessage().getMentions().size() > 0) {
for (IUser user : event.getMessage().getMentions()) {
content.append(user.getName()).append(": ").append(user.getCreationDate().format(formatter)).append("\n");
}
} else {
content.append("No User specified");
}
BotUtils.sendMessage(event.getChannel(), content.toString(), false);
}).start();
return true;
}

/**
* Send a invitation
*
@@ -70,10 +100,10 @@ public class InfoCommands extends Module implements Fast {
)
public boolean inviteBot(MessageReceivedEvent event, String[] args) {
if (event.getAuthor().equals(DiscordInit.getInstance().getDiscordClient().getApplicationOwner())) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("command_success")), true);
EnumSet<Permissions> permissions = EnumSet.allOf(Permissions.class);
BotInviteBuilder builder = new BotInviteBuilder(INIT.BOT).withPermissions(permissions);
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);
}
@@ -81,6 +111,46 @@ public class InfoCommands extends Module implements Fast {
return true;
}

/**
* Send a invitation
*
* @param event MessageEvent
* @param args Argumente [Not needed]
* @return state
*/
@Command(
command = "createInvite",
description = "Invites the bot",
alias = "crei",
arguments = {"Server ID"},
permission = Globals.BOT_OWNER,
prefix = Globals.ADMIN_PREFIX
)
public boolean createInvite(MessageReceivedEvent event, String[] args) {
Console.debug("Creating Invite link to Server: " + args[0]);
if (INIT.BOT.getGuildByID(Long.valueOf(args[0])) != null) {
IChannel channel = INIT.BOT.getGuildByID(Long.valueOf(args[0])).getGeneralChannel();
if (channel == null) {
channel = INIT.BOT.getGuildByID(Long.valueOf(args[0])).getChannels().get(0);
}
if (channel != null) {
IInvite invite = channel.createInvite(0, 1, false, false);
if (invite != null) {
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), invite.toString() + " |||| " + invite.getCode(), false);
} else {
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), "The Bot cant create a InviteLink", false);
}
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("command_success")), true);
} else {
BotUtils.sendPrivMessage(event.getAuthor().getOrCreatePMChannel(), "No Channel found", false);
return false;
}
return true;
} else {
return false;
}
}

/**
* Stats Command
*
@@ -136,13 +206,11 @@ public class InfoCommands extends Module implements Fast {
builders.get(page - 1).appendDescription(LANG.getTranslation("help_prefixinfo"));
int count = 0;
for (Command command : COMMAND.getAllCommands()) {
if (PERM.hasPermission(event.getAuthor(), event.getGuild(), command.permission())) {
String string = "\n" + LANG.getTranslation("help_alias") + ": | " + botprefix + command.prefix() + command.alias() +
"\n" + LANG.getTranslation("help_arguments") + ": | " + Arrays.toString(command.arguments()).replace("[", "").replace("]", "") +
"\n" + LANG.getTranslation("help_description") + ": | " + LANG.getMethodDescription(command) +
"\n" + LANG.getTranslation("help_permission") + ": | " + command.permission() + "\n";
builders.get(page - 1).appendField((count+1)+". "+LANG.getTranslation("help_command") + " | " + botprefix + command.prefix() + command.command(), string, false);
}
String string = "\n" + LANG.getTranslation("help_alias") + ": | " + botprefix + command.prefix() + command.alias() +
"\n" + LANG.getTranslation("help_arguments") + ": | " + Arrays.toString(command.arguments()).replace("[", "").replace("]", "") +
"\n" + LANG.getTranslation("help_description") + ": | " + LANG.getMethodDescription(command) +
"\n" + LANG.getTranslation("help_permission") + ": | " + command.permission() + "\n";
builders.get(page - 1).appendField((count + 1) + ". " + LANG.getTranslation("help_command") + " | " + botprefix + command.prefix() + command.command(), string, false);
if (builders.get(page - 1).getFieldCount() >= EmbedBuilder.FIELD_COUNT_LIMIT || builders.get(page - 1).getTotalVisibleCharacters() >= (EmbedBuilder.MAX_CHAR_LIMIT - 1000)) {
page++;
EmbedBuilder buildertemp = new EmbedBuilder();
@@ -152,12 +220,12 @@ public class InfoCommands extends Module implements Fast {
builders.get(page - 1).withTitle(":information_source: " + LANG.getTranslation("help_title") + " Page: " + page + " :information_source:");
builders.get(page - 1).withColor(Color.CYAN);
}
builders.get(0).withTitle(":information_source: " + LANG.getTranslation("help_title") + "(" + count + ")" + " Page: " + 1 + " :information_source:");
builders.get(0).withTitle(":information_source: " + LANG.getTranslation("help_title") + "(" + count + ")" + LANG.getTranslation("help_page") + 1 + " :information_source:");
return builders;
}

@LanguageMethod(
languagestringcount = 16
languagestringcount = 18
)
@Override
public void setdefaultLanguage() {
@@ -169,9 +237,12 @@ public class InfoCommands extends Module implements Fast {
DRIVER.setProperty(DEF_LANG, "stats_user", "Users");
DRIVER.setProperty(DEF_LANG, "stats_commands", "Commands");
DRIVER.setProperty(DEF_LANG, "stats_uptime", "Uptime");
DRIVER.setProperty(DEF_LANG, "stats_ram", "Ram Usage");
DRIVER.setProperty(DEF_LANG, "stats_shard_ping", "Ping for Shard");

//Help Command
DRIVER.setProperty(DEF_LANG, "help_title", "All Commands");
DRIVER.setProperty(DEF_LANG, "help_page", "Page");
DRIVER.setProperty(DEF_LANG, "help_command", "Command");
DRIVER.setProperty(DEF_LANG, "help_alias", "Alias");
DRIVER.setProperty(DEF_LANG, "help_arguments", "Arguments");


+ 35
- 34
src/main/java/modules/Moderation.java View File

@@ -21,12 +21,13 @@ import java.util.List;
* Created by N.Hartmann on 28.06.2017.
* Copyright 2017
*/
public class Moderation extends Module implements Fast{
public class Moderation extends Module implements Fast {

/**
* Deletes a List Message
*
* @param event MessageEvent
* @param args Argumente [Not needed]
* @param args Argumente [Not needed]
* @return state
*/
@Command(
@@ -42,32 +43,31 @@ public class Moderation extends Module implements Fast{
int total = 0;
try {
IChannel channel = event.getChannel();
String origintopic = channel.getTopic();
MessageHistory messages = channel.getMessageHistory(Integer.parseInt(args[0]));
if (messages.getLatestMessage().getLongID() == event.getMessage().getLongID()) {
while (!event.getMessage().isDeleted()) {
Thread.sleep(200);
}
messages = channel.getMessageHistory(Integer.parseInt(args[0]));
MessageHistory messages = channel.getMessageHistory(Integer.parseInt(args[0]));
BotUtils.bulkdeleteMessage(channel, messages);
if (messages.getLatestMessage().getLongID() == event.getMessage().getLongID()) {
while (!event.getMessage().isDeleted()) {
Thread.sleep(200);
}
total = messages.size();
BotUtils.bulkdeleteMessage(channel, messages);
channel.changeTopic(origintopic + " ["+String.format(LANG.getTranslation("del_topic"), total, total)+"]");
Console.debug(Console.sendprefix+"DM: "+total);
Thread.sleep(2000);
channel.changeTopic(origintopic);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS+LANG.getTranslation("command_success")), true);
messages = channel.getMessageHistory(Integer.parseInt(args[0]));
}
total = messages.size();

Thread.sleep(2000);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("del_wait_success")), true);
} catch (Exception ex) {
BotUtils.sendMessage(event.getChannel(), LANG.ERROR+String.format(LANG.getTranslation("deletion_error"), total, total, ex.getMessage()), true);
BotUtils.sendMessage(event.getChannel(), LANG.ERROR + String.format(LANG.getTranslation("deletion_error"), total, total, ex.getMessage()), true);
}
}).start();

return true;
}

/**
* Force Deletes a List Message
*
* @param event MessageEvent
* @param args Argumente [Not needed]
* @param args Argumente [Not needed]
* @return state
*/
@Command(
@@ -85,32 +85,30 @@ public class Moderation extends Module implements Fast{
try {
IChannel channel = event.getChannel();
String origintopic = channel.getTopic();
MessageHistory messages = channel.getMessageHistory(Integer.parseInt(args[0]));
MessageHistory messages = channel.getMessageHistory(Integer.parseInt(args[0]));
if (messages.getLatestMessage().getLongID() == event.getMessage().getLongID()) {
while (!event.getMessage().isDeleted()) {
Thread.sleep(200);
}
messages = channel.getMessageHistory(Integer.parseInt(args[0]));
}
total = messages.size();
for (IMessage message: messages) {
if (!message.isDeleted()) {
BotUtils.deleteMessageOne(message);
count++;
channel.changeTopic(origintopic + " ["+String.format(LANG.getTranslation("del_topic"), count, total)+"]");
}
total = messages.size();
for (IMessage message : messages) {
if (!message.isDeleted()) {
BotUtils.deleteMessageOne(message);
count++;
}
Thread.sleep(1000);
channel.changeTopic(origintopic);
Console.debug(Console.sendprefix+"FDM: "+count+" of "+total);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS+LANG.getTranslation("command_success")), true);
}
Thread.sleep(1000);
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.SUCCESS + LANG.getTranslation("del_wait_success")), true);
} catch (Exception ex) {
BotUtils.sendMessage(event.getChannel(), LANG.ERROR+String.format(LANG.getTranslation("deletion_error"), count, total, ex.getMessage()), true);
BotUtils.sendMessage(event.getChannel(), LANG.ERROR + String.format(LANG.getTranslation("deletion_error"), count, total, ex.getMessage()), true);
}
}).start();

return true;
}

@Command(
command = "shutdown",
description = "Shutdown the bot",
@@ -126,11 +124,12 @@ public class Moderation extends Module implements Fast{
Thread.sleep(10000);
System.exit(0);
} catch (Exception ex) {
Console.error("Error on shutdown: "+ex.getMessage());
Console.error("Error on shutdown: " + ex.getMessage());
}
}).start();
return true;
}

@Command(
command = "deleteprivmsg",
description = "Shutdown the bot",
@@ -144,7 +143,7 @@ public class Moderation extends Module implements Fast{
try {
IPrivateChannel privateChannel = event.getAuthor().getOrCreatePMChannel();
List<IMessage> messageList = privateChannel.getMessageHistory(Integer.parseInt(args[0]));
for (IMessage message: messageList) {
for (IMessage message : messageList) {
if (message.getAuthor().isBot()) {
BotUtils.deleteMessageOne(message);
}
@@ -156,12 +155,14 @@ public class Moderation extends Module implements Fast{
}).start();
return true;
}

@LanguageMethod(
languagestringcount = 1
languagestringcount = 2
)
@Override
public void setdefaultLanguage() {
//Deletion
DRIVER.setProperty(DEF_LANG, "del_topic", "Deletion %1s of %2s");
DRIVER.setProperty(DEF_LANG, "del_wait_success", "Deletion invoked... Wait until messages disapear.");
}
}

+ 3
- 3
src/main/java/modules/Permission.java View File

@@ -59,7 +59,7 @@ public class Permission extends Module implements Fast {
}
} catch (Exception ex) {
Console.error("Error on adding Permission" + ex.getMessage());
ex.printStackTrace();
Console.error(ex);
}

}
@@ -103,7 +103,7 @@ public class Permission extends Module implements Fast {
}
} catch (Exception ex) {
Console.error("Error on adding Permission" + ex.getMessage());
ex.printStackTrace();
Console.error(ex);
}

}
@@ -153,7 +153,7 @@ public class Permission extends Module implements Fast {
}
} catch (Exception ex) {
Console.error("Error on adding Permission" + ex.getMessage());
ex.printStackTrace();
Console.error(ex);
}

}


+ 8
- 16
src/main/java/modules/RoleManagement.java View File

@@ -34,7 +34,7 @@ public class RoleManagement extends Module implements Fast {
description = "Add a User to a specific role",
arguments = {"User Mention", "Role []"},
prefix = Globals.ADMIN_PREFIX,
permission = "role_manage",
permission = Globals.BOT_MANAGE,
alias = "aur"
)
public void addUsertoRole(MessageReceivedEvent event, String[] args) {
@@ -48,7 +48,7 @@ public class RoleManagement extends Module implements Fast {
}
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), Arrays.toString(ex.getStackTrace()))), true);
ex.printStackTrace();
Console.error(ex);
}
}

@@ -57,7 +57,7 @@ public class RoleManagement extends Module implements Fast {
description = "Add a User to a specific role",
arguments = {"User Mention", "Role []"},
prefix = Globals.ADMIN_PREFIX,
permission = "role_manage",
permission = Globals.BOT_MANAGE,
alias = "rmur"
)
public void removeUsertoRole(MessageReceivedEvent event, String[] args) {
@@ -71,14 +71,14 @@ public class RoleManagement extends Module implements Fast {
}
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), Arrays.toString(ex.getStackTrace()))), true);
ex.printStackTrace();
Console.error(ex);
}
}

@Command(
command = "definegenderrole",
description = "Add a User to a specific role",
arguments = {"Gender (m or w)", "Role []"},
arguments = {"Gender (m or f)", "Role []"},
prefix = Globals.ADMIN_PREFIX,
permission = "role_manage",
alias = "dgr"
@@ -101,7 +101,7 @@ public class RoleManagement extends Module implements Fast {
}
} catch (Exception ex) {
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(String.format(LANG.getTranslation("commonmessage_error"), Arrays.toString(ex.getStackTrace()))), true);
ex.printStackTrace();
Console.error(ex);
}
}

@@ -126,7 +126,6 @@ public class RoleManagement extends Module implements Fast {
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());
@@ -134,14 +133,10 @@ public class RoleManagement extends Module implements Fast {
JSONObject femaleobj = new JSONObject();
femaleobj.put(iGuild.getStringID(), roleids);
femaleserverids.add(femaleobj);
} 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());
@@ -149,9 +144,6 @@ public class RoleManagement extends Module implements Fast {
JSONObject femaleobj = new JSONObject();
femaleobj.put(iGuild.getStringID(), roleids);
maleserverids.add(femaleobj);
} 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);
@@ -159,7 +151,7 @@ public class RoleManagement extends Module implements Fast {
DRIVER.setProperty(GENDER, "gendersave", root);
DRIVER.saveJson();
} catch (Exception ex) {
ex.printStackTrace();
Console.error(ex);
}
}

@@ -180,7 +172,7 @@ public class RoleManagement extends Module implements Fast {
}
}
} catch (Exception ex) {
ex.printStackTrace();
Console.error(ex);
}
}



+ 1
- 1
src/main/java/modules/SearchCommand.java View File

@@ -68,7 +68,7 @@ public class SearchCommand extends Module implements Fast{
BotUtils.sendEmbMessage(event.getChannel(), SMB.shortMessage(LANG.getTranslation("engine_unknown")), true);
}
} catch (Exception ex) {
ex.printStackTrace();
Console.error(ex);
}
}).start();



+ 3
- 6
src/main/java/modules/ServerManager.java View File

@@ -8,10 +8,7 @@ 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 util.*;

import java.awt.*;
import java.util.List;
@@ -35,7 +32,7 @@ public class ServerManager extends Module implements Fast{
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();
Console.error(ex);
}
return true;
}
@@ -55,7 +52,7 @@ public class ServerManager extends Module implements Fast{
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();
Console.error(ex);
}
return true;
}


+ 2
- 2
src/main/java/permission/PermissionController.java View File

@@ -145,7 +145,7 @@ public class PermissionController implements Fast {
DRIVER.saveJson();
} catch (Exception ex) {
Console.error("Saving of Permissions failed");
ex.printStackTrace();
Console.error(ex);
}
}

@@ -178,7 +178,7 @@ public class PermissionController implements Fast {
}
} catch (Exception ex) {
Console.error("Failed to load Permissions");
ex.printStackTrace();
Console.error(ex);
}
}



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

@@ -72,7 +72,7 @@ public class FileDriver {
loadJson();
} catch (Exception ex) {
Console.error("File can not be accessed: "+filenamewithpath);
ex.printStackTrace();
Console.error(ex);
MoMuOSBMain.shutdown();
}
}
@@ -91,7 +91,7 @@ public class FileDriver {
}
} catch (Exception ex) {
Console.error("Parsing error");
ex.printStackTrace();
Console.error(ex);
}
return json;
}
@@ -115,7 +115,7 @@ public class FileDriver {

} catch (Exception ex) {
Console.error("File can not be loaded");
ex.printStackTrace();
Console.error(ex);
MoMuOSBMain.shutdown();
}
}
@@ -135,7 +135,7 @@ public class FileDriver {
}
} catch (Exception ex) {
Console.error("File can not be saved");
ex.printStackTrace();
Console.error(ex);
MoMuOSBMain.shutdown();
}
}
@@ -160,7 +160,7 @@ public class FileDriver {
}
} catch (Exception ex) {
Console.error("Can not set Property: ");
ex.printStackTrace();
Console.error(ex);
}
}

@@ -178,7 +178,7 @@ public class FileDriver {
}
} catch (Exception ex) {
setProperty(filename, option, defaultvalue);
ex.printStackTrace();
Console.error(ex);
}
return jsons.get(filename).get(option);
}
@@ -187,7 +187,7 @@ public class FileDriver {
try {
return jsons.get(filename).has(option);
} catch (Exception ex) {
ex.printStackTrace();
Console.error(ex);
}
return false;
}
@@ -219,7 +219,7 @@ public class FileDriver {
}
} catch (Exception ex) {
Console.error("Can not remove Property: ");
ex.printStackTrace();
Console.error(ex);
}
}

@@ -231,7 +231,7 @@ public class FileDriver {
}
} catch (Exception ex) {
Console.error("Can not list Property: ");
ex.printStackTrace();
Console.error(ex);
}
return objects;
}


+ 1
- 1
src/main/java/storage/WebClient.java View File

@@ -57,7 +57,7 @@ public class WebClient
}
catch ( Exception ex )
{
ex.printStackTrace();
Console.error(ex);
//If something went wrong.
return "{'error' : '"+ex.getMessage()+"'}";


+ 12
- 1
src/main/java/util/Console.java View File

@@ -42,7 +42,18 @@ public class Console implements Fast{
String[] parts = message.split("\n");
for (String part: parts) {
System.out.println(Utils.format(getTimeNow())+prefix + errorprefix + part);
logger.info(prefix + errorprefix + part);
logger.error(prefix + errorprefix + part);
}
}
/**
* Error message
* @param message message
*/
public static void error(Exception message) {
String errorprefix = "[ERROR]";
for(StackTraceElement stackTraceElement : message.getStackTrace()) {
System.out.println(Utils.format(getTimeNow())+prefix + errorprefix + System.lineSeparator() + stackTraceElement.toString());
logger.error(prefix+ errorprefix + System.lineSeparator() + stackTraceElement.toString());
}
}



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

@@ -49,7 +49,7 @@ public class GetAnnotation implements Fast{
}
} catch (Exception ex) {
Console.error(String.format(LANG.getTranslation("annotation_error"), clazz.getName(), ex.getMessage()));
ex.printStackTrace();
Console.error(ex);
}
return allannotation;
}


+ 16
- 7
src/main/resources/log4j.properties View File

@@ -1,12 +1,21 @@
# Root logger option
log4j.rootLogger=DEBUG, RollingAppender
log4j.rootLogger=DEBUG, debuglog, errorlog

log4j.appender.RollingAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.RollingAppender.File=./logs/discord4j.log
log4j.appender.RollingAppender.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.RollingAppender.Threshold=INFO
log4j.appender.RollingAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.RollingAppender.layout.ConversionPattern=%d - %m%n
log4j.appender.debuglog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.debuglog.File=./logs/debug.log
log4j.appender.debuglog.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.debuglog.Threshold=INFO
log4j.appender.debuglog.layout=org.apache.log4j.PatternLayout
log4j.appender.debuglog.layout.ConversionPattern=%d - %m%n
log4j.appender.debuglog.MaxBackupIndex=7

log4j.appender.errorlog=org.apache.log4j.DailyRollingFileAppender
log4j.appender.errorlog.File=./logs/warn.log
log4j.appender.errorlog.DatePattern='.'yyyy-MM-dd'.log'
log4j.appender.errorlog.Threshold=WARN
log4j.appender.errorlog.layout=org.apache.log4j.PatternLayout
log4j.appender.errorlog.layout.ConversionPattern=%d - %m%n
log4j.appender.errorlog.MaxBackupIndex=7

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender


Loading…
Cancel
Save