From 35296a2d85ea140ffdfd9395a8335ad9857d09d8 Mon Sep 17 00:00:00 2001 From: duncte123 Date: Sat, 25 Nov 2017 10:14:29 +0100 Subject: [PATCH 1/7] Forgot to remove something --- src/main/java/ml/duncte123/skybot/BotListener.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/java/ml/duncte123/skybot/BotListener.java b/src/main/java/ml/duncte123/skybot/BotListener.java index 5a7d044e4..7d891fb6d 100644 --- a/src/main/java/ml/duncte123/skybot/BotListener.java +++ b/src/main/java/ml/duncte123/skybot/BotListener.java @@ -21,7 +21,6 @@ import ml.duncte123.skybot.commands.essentials.eval.EvalCommand; import ml.duncte123.skybot.objects.guild.GuildSettings; -import ml.duncte123.skybot.parsers.CommandParser; import ml.duncte123.skybot.utils.*; import net.dv8tion.jda.bot.sharding.ShardManager; import net.dv8tion.jda.core.JDA; @@ -30,7 +29,6 @@ import net.dv8tion.jda.core.entities.Message; import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.core.events.ReadyEvent; -import net.dv8tion.jda.core.events.ShutdownEvent; import net.dv8tion.jda.core.events.guild.GuildJoinEvent; import net.dv8tion.jda.core.events.guild.GuildLeaveEvent; import net.dv8tion.jda.core.events.guild.member.GuildMemberJoinEvent; @@ -38,22 +36,18 @@ import net.dv8tion.jda.core.events.guild.voice.GuildVoiceMoveEvent; import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.core.hooks.ListenerAdapter; -import org.apache.commons.lang3.time.DateUtils; import org.slf4j.event.Level; import java.sql.SQLException; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.regex.Pattern; public class BotListener extends ListenerAdapter { - - /** - * This is the command parser - */ - private static CommandParser parser = new CommandParser(); /** * This filter helps us to fiter out swearing From 1f697db9a986b8ae57ae31ef47b7dd0b5345d384 Mon Sep 17 00:00:00 2001 From: duncte123 Date: Sat, 25 Nov 2017 10:40:45 +0100 Subject: [PATCH 2/7] Change embed colour --- build.gradle | 2 +- src/main/java/ml/duncte123/skybot/utils/AirUtils.java | 2 +- src/main/java/ml/duncte123/skybot/utils/Settings.java | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 8a184b79b..539c572e1 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,7 @@ apply plugin: 'groovy' group = 'ml.duncte123.skybot' -version '3.51.3' +version '3.51.4' compileGroovy.options.encoding = "UTF-8" diff --git a/src/main/java/ml/duncte123/skybot/utils/AirUtils.java b/src/main/java/ml/duncte123/skybot/utils/AirUtils.java index 32556da1a..e591db1b3 100644 --- a/src/main/java/ml/duncte123/skybot/utils/AirUtils.java +++ b/src/main/java/ml/duncte123/skybot/utils/AirUtils.java @@ -598,7 +598,7 @@ public static void stop() { } public static TextChannel getLogChannel(String channelId, Guild guild) { - if(channelId == null) return getPublicChannel(guild); + if(channelId == null || channelId.isEmpty()) return getPublicChannel(guild); TextChannel tc; try{ diff --git a/src/main/java/ml/duncte123/skybot/utils/Settings.java b/src/main/java/ml/duncte123/skybot/utils/Settings.java index 9c5bbecef..580a7b21a 100644 --- a/src/main/java/ml/duncte123/skybot/utils/Settings.java +++ b/src/main/java/ml/duncte123/skybot/utils/Settings.java @@ -21,9 +21,8 @@ import ml.duncte123.skybot.BuildConfig; -import java.awt.*; - -import static java.awt.Color.RED; +import java.awt.Color; +import static java.awt.Color.decode; public class Settings { /** @@ -70,5 +69,5 @@ public class Settings { /** * The colour of the bar that your embed has */ - public static final Color defaultColour = RED; + public static final Color defaultColour = decode("#0751c6"); } From c0a9f9ee109b71a22921dd3d2a67c60b10f80b98 Mon Sep 17 00:00:00 2001 From: Duncan Sterken Date: Sat, 25 Nov 2017 11:38:58 +0100 Subject: [PATCH 3/7] Add check for the updater --- src/main/java/ml/duncte123/skybot/SkyBot.java | 1 - src/main/java/ml/duncte123/skybot/utils/Settings.java | 5 +++++ .../ml/duncte123/skybot/RegisterKotlinCommands.kt | 1 - .../skybot/commands/essentials/UpdateCommand.kt | 10 +++++++++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/ml/duncte123/skybot/SkyBot.java b/src/main/java/ml/duncte123/skybot/SkyBot.java index ee0e8cff7..d29bcca2c 100644 --- a/src/main/java/ml/duncte123/skybot/SkyBot.java +++ b/src/main/java/ml/duncte123/skybot/SkyBot.java @@ -46,7 +46,6 @@ public class SkyBot { */ @Deprecated public static void main(String... args) throws Exception { - //Set the logger to only info by default Logger l = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME); l.setLevel(ch.qos.logback.classic.Level.INFO); diff --git a/src/main/java/ml/duncte123/skybot/utils/Settings.java b/src/main/java/ml/duncte123/skybot/utils/Settings.java index 580a7b21a..eede73309 100644 --- a/src/main/java/ml/duncte123/skybot/utils/Settings.java +++ b/src/main/java/ml/duncte123/skybot/utils/Settings.java @@ -30,6 +30,11 @@ public class Settings { */ public static final String ownerId = BuildConfig.ownerId; + /** + * This holds the value if the updater command should update the bot or return an error + */ + public static final boolean enableUpdaterCommand = System.getProperty("updater") != null; + /** * This contains a list of different id's * diff --git a/src/main/kotlin/ml/duncte123/skybot/RegisterKotlinCommands.kt b/src/main/kotlin/ml/duncte123/skybot/RegisterKotlinCommands.kt index 19e18734f..b4c28ecb5 100644 --- a/src/main/kotlin/ml/duncte123/skybot/RegisterKotlinCommands.kt +++ b/src/main/kotlin/ml/duncte123/skybot/RegisterKotlinCommands.kt @@ -21,7 +21,6 @@ package ml.duncte123.skybot import ml.duncte123.skybot.commands.`fun`.BlobCommand import ml.duncte123.skybot.commands.animals.BirbCommand -import ml.duncte123.skybot.commands.animals.BirbCommandJava import ml.duncte123.skybot.commands.essentials.RestartCommand import ml.duncte123.skybot.commands.essentials.UpdateCommand import ml.duncte123.skybot.commands.uncategorized.OneLinerCommands diff --git a/src/main/kotlin/ml/duncte123/skybot/commands/essentials/UpdateCommand.kt b/src/main/kotlin/ml/duncte123/skybot/commands/essentials/UpdateCommand.kt index 9cf1d24aa..49ef63bcb 100644 --- a/src/main/kotlin/ml/duncte123/skybot/commands/essentials/UpdateCommand.kt +++ b/src/main/kotlin/ml/duncte123/skybot/commands/essentials/UpdateCommand.kt @@ -3,6 +3,7 @@ package ml.duncte123.skybot.commands.essentials import ml.duncte123.skybot.objects.command.Command import ml.duncte123.skybot.objects.command.CommandCategory import ml.duncte123.skybot.utils.AirUtils +import ml.duncte123.skybot.utils.EmbedUtils import ml.duncte123.skybot.utils.Settings import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent import java.util.* @@ -20,8 +21,15 @@ class UpdateCommand: Command() { sendError(event.message) return } + + if(!Settings.enableUpdaterCommand) { + val message = "The updater is not enabled. " + + "If you wish to use the updater you need to download it from [this page](https://github.com/ramidzkh/SkyBot-Updater/releases)." + sendEmbed(event, EmbedUtils.embedMessage(message)) + return + } - event.channel.sendMessage("✅ Updating").queue() + sendMsg(event, "✅ Updating") // This will also shutdown eval event.jda.asBot().shardManager.shutdown() From 794b34b2df40741e786d97dd3216141ef6151b10 Mon Sep 17 00:00:00 2001 From: Ramid Khan Date: Sat, 25 Nov 2017 21:42:39 +1100 Subject: [PATCH 4/7] Add some basic stuff to eval filter --- .../skybot/commands/essentials/eval/filter/EvalFilter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/ml/duncte123/skybot/commands/essentials/eval/filter/EvalFilter.java b/src/main/java/ml/duncte123/skybot/commands/essentials/eval/filter/EvalFilter.java index a2e6f474a..36ca179be 100644 --- a/src/main/java/ml/duncte123/skybot/commands/essentials/eval/filter/EvalFilter.java +++ b/src/main/java/ml/duncte123/skybot/commands/essentials/eval/filter/EvalFilter.java @@ -48,6 +48,8 @@ public class EvalFilter extends GroovyValueFilter { private static final Class[] ALLOWED_TYPES_LIST = { Math.class, String.class, + StringBuilder.class, + StringBuffer.class, Boolean.class, boolean.class, From 218d7158e3d6f00c5005d40f78739dc82c867c24 Mon Sep 17 00:00:00 2001 From: Duncan Sterken Date: Sat, 25 Nov 2017 11:56:39 +0100 Subject: [PATCH 5/7] Change the script name --- .../skybot/objects/delegate/ScriptDelegate.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java b/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java index cc55edbf9..b5ca3298f 100644 --- a/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java +++ b/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java @@ -19,6 +19,7 @@ package ml.duncte123.skybot.objects.delegate; import Java.lang.VRCubeException; +import groovy.lang.GroovyShell; import groovy.lang.Script; import org.codehaus.groovy.control.CompilationFailedException; @@ -26,6 +27,7 @@ import java.io.IOException; public class ScriptDelegate extends Script { + private int counter; public ScriptDelegate(Script s) { super(s.getBinding()); @@ -75,4 +77,13 @@ public Object evaluate(File file) throws CompilationFailedException, IOException public void run(File file, String[] arguments) throws CompilationFailedException, IOException { throw new VRCubeException("Erm, no?"); } + + private synchronized String generateScriptName() { + return "Script" + (++counter); + } + + @Override + public String toString() { + return generateScriptName(); + } } From 0524c430ef5cd113a5e84b307c98bcd6d5b559a7 Mon Sep 17 00:00:00 2001 From: Duncan Sterken Date: Sat, 25 Nov 2017 13:44:36 +0100 Subject: [PATCH 6/7] Stupid feature, it's disabled (for now) --- .../java/ml/duncte123/skybot/BotListener.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/ml/duncte123/skybot/BotListener.java b/src/main/java/ml/duncte123/skybot/BotListener.java index 7d891fb6d..520638e04 100644 --- a/src/main/java/ml/duncte123/skybot/BotListener.java +++ b/src/main/java/ml/duncte123/skybot/BotListener.java @@ -223,19 +223,20 @@ public void onGuildMemberJoin(GuildMemberJoinEvent event) { */ @Override public void onGuildJoin(GuildJoinEvent event) { + //Temp disable that //if 60 of a guild is bots, we'll leave it - double[] botToUserRatio = AirUtils.getBotRatio(event.getGuild()); - if (botToUserRatio[1] > 60) { - AirUtils.getPublicChannel(event.getGuild()).sendMessage(String.format("Hey %s, %s%s of this guild are bots (%s is the total btw). Iḿ outta here.", - event.getGuild().getOwner().getAsMention(), - botToUserRatio[1], - "%", - event.getGuild().getMemberCache().size())).queue( - message -> message.getGuild().leave().queue() - ); - AirUtils.log(Settings.defaultName + "GuildJoin", Level.INFO, "Joining guild: " + event.getGuild().getName() + ", and leaving it after. BOT ALERT"); - return; - } +// double[] botToUserRatio = AirUtils.getBotRatio(event.getGuild()); +// if (botToUserRatio[1] > 60) { +// AirUtils.getPublicChannel(event.getGuild()).sendMessage(String.format("Hey %s, %s%s of this guild are bots (%s is the total btw). Iḿ outta here.", +// event.getGuild().getOwner().getAsMention(), +// botToUserRatio[1], +// "%", +// event.getGuild().getMemberCache().size())).queue( +// message -> message.getGuild().leave().queue() +// ); +// AirUtils.log(Settings.defaultName + "GuildJoin", Level.INFO, "Joining guild: " + event.getGuild().getName() + ", and leaving it after. BOT ALERT"); +// return; +// } AirUtils.log(Settings.defaultName + "GuildJoin", Level.INFO, "Joining guild: " + event.getGuild().getName() + "."); GuildSettingsUtils.registerNewGuild(event.getGuild()); AirUtils.updateGuildCount(event.getJDA(), event.getJDA().asBot().getShardManager().getGuildCache().size()); From ab56e4a7b570bf9a0f478547a19adae0856a6130 Mon Sep 17 00:00:00 2001 From: Duncan Sterken Date: Sat, 25 Nov 2017 13:54:00 +0100 Subject: [PATCH 7/7] Hotfix for open eval --- .../duncte123/skybot/objects/delegate/ScriptDelegate.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java b/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java index b5ca3298f..dad70c676 100644 --- a/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java +++ b/src/main/java/ml/duncte123/skybot/objects/delegate/ScriptDelegate.java @@ -78,6 +78,14 @@ public void run(File file, String[] arguments) throws CompilationFailedException throw new VRCubeException("Erm, no?"); } + public Object dump() { + return "\uD83D\uDEAE"; + } + + public Object find() { + return "You will never find me."; + } + private synchronized String generateScriptName() { return "Script" + (++counter); }