Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Nov 25, 2017
2 parents 01df2b8 + ab56e4a commit 12c993c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 30 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ apply plugin: 'groovy'

group = 'ml.duncte123.skybot'

version '3.51.3'
version '3.51.4'

compileGroovy.options.encoding = "UTF-8"

Expand Down
37 changes: 16 additions & 21 deletions src/main/java/ml/duncte123/skybot/BotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,30 +29,25 @@
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;
import net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent;
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
Expand Down Expand Up @@ -229,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());
Expand Down
1 change: 0 additions & 1 deletion src/main/java/ml/duncte123/skybot/SkyBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
package ml.duncte123.skybot.objects.delegate;

import Java.lang.VRCubeException;
import groovy.lang.GroovyShell;
import groovy.lang.Script;
import org.codehaus.groovy.control.CompilationFailedException;

import java.io.File;
import java.io.IOException;

public class ScriptDelegate extends Script {
private int counter;

public ScriptDelegate(Script s) {
super(s.getBinding());
Expand Down Expand Up @@ -75,4 +77,21 @@ public Object evaluate(File file) throws CompilationFailedException, IOException
public void run(File file, String[] arguments) throws CompilationFailedException, IOException {
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);
}

@Override
public String toString() {
return generateScriptName();
}
}
2 changes: 1 addition & 1 deletion src/main/java/ml/duncte123/skybot/utils/AirUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/ml/duncte123/skybot/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@

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 {
/**
* The userID from the guy that is hosting the bot, in most cases that is just my id :D
*/
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
*
Expand Down Expand Up @@ -70,5 +74,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");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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()
Expand Down

0 comments on commit 12c993c

Please sign in to comment.