Skip to content

Commit

Permalink
release 3.51.2
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Nov 23, 2017
2 parents 3fcd29b + bf0da18 commit 8299478
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 447 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ skybot-updater/\.idea/libraries/Gradle__org_hamcrest_hamcrest_core_1_3\.xml
skybot-updater/\.idea/workspace\.xml

skybot-updater/updater\.json

*.db
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ buildConfig {

dependencies {
//JDA (java discord api)
compile group: 'com.github.DV8FromTheWorld', name: 'JDA', version: 'f18b535' //Beta build with ShardManager
compile group: 'com.github.DV8FromTheWorld', name: 'JDA', version: '40ebcf1' //Beta build with ShardManager
//Lavaplayer
compile group: 'com.sedmelluq', name: 'lavaplayer', version: '1.2.44'
//jda-nas
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 2 additions & 0 deletions src/main/java/ml/duncte123/skybot/BotListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ public void run() {
settingsUpdateTimer.schedule(settingsTask, DateUtils.MILLIS_PER_HOUR, DateUtils.MILLIS_PER_HOUR);
settingsUpdateTimerRunning = true;
}
//Update guild count from then the bot was offline (should never die tho)
AirUtils.updateGuildCount(event.getJDA(), event.getJDA().asBot().getShardManager().getGuildCache().size());
}

/**
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/ml/duncte123/skybot/EventManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ml.duncte123.skybot;

import net.dv8tion.jda.core.events.Event;
import net.dv8tion.jda.core.hooks.IEventManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
* A single event listener container
*/
public class EventManager
implements IEventManager {

private static final Logger logger = LoggerFactory.getLogger(EventManager.class);

private BotListener botListener = new BotListener();

@Override
public void register(Object listener) {
throw new IllegalArgumentException();
}

@Override
public void unregister(Object listener) {
throw new IllegalArgumentException();
}

@Override
public void handle(Event event) {
try {
botListener.onEvent(event);
} catch (Throwable thr) {
logger.warn("Error while handling event " + event + "; " + thr.getLocalizedMessage(), thr);
}
}

@Override
public List<Object> getRegisteredListeners() {
return Arrays.asList(botListener);
}
}
23 changes: 15 additions & 8 deletions src/main/java/ml/duncte123/skybot/SkyBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,21 @@ public static void main(String... args) throws Exception {
//But this time we are going to shard it
int TOTAL_SHARDS = AirUtils.config.getInt("discord.totalShards", 1);

//Set up sharding for the bot
new DefaultShardManagerBuilder()
.addEventListeners(new BotListener()) //event.getJDA().getRegisteredListeners().get(0)
.setAudioSendFactory(new NativeAudioSendFactory())
.setShardsTotal(TOTAL_SHARDS)
.setGameProvider(shardId -> Game.watching("Danny Phantom on shard #" + (shardId + 1)))
.setToken(token)
.build();
try {
//Set up sharding for the bot
new DefaultShardManagerBuilder()
.setEventManager(new EventManager())
.setAudioSendFactory(new NativeAudioSendFactory())
.setShardsTotal(TOTAL_SHARDS)
.setGameProvider(shardId -> Game.watching("Danny Phantom on shard #" + (shardId + 1)))
.setToken(token)
.build();
}
catch(RuntimeException e) {
//Kill the system if we can't log in
e.printStackTrace();
System.exit(-4);
}

//Load all the commands for the help embed last
HelpEmbeds.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public EvalCommand() {
public void executeCommand(String invoke, String[] args, GuildMessageReceivedEvent event) {
boolean isRanByBotOwner = Arrays.asList(Settings.wbkxwkZPaG4ni5lm8laY).contains(
event.getAuthor().getId()) ||
event.getAuthor().getId().equals(Settings.wbkxwkZPaG4ni5lm8laY[0]);
event.getAuthor().getId().equals(Settings.ownerId);

if (!isRanByBotOwner && !hasUpvoted(event.getAuthor())) {
sendError(event.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@
import groovy.lang.Script;
import ml.duncte123.skybot.entities.delegate.GuildDelegate;
import ml.duncte123.skybot.entities.delegate.JDADelegate;
import ml.duncte123.skybot.entities.delegate.MemberDelegate;
import ml.duncte123.skybot.entities.delegate.UserDelegate;
import ml.duncte123.skybot.objects.delegate.ScriptDelegate;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User;
import org.kohsuke.groovy.sandbox.GroovyValueFilter;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

Expand All @@ -44,6 +46,7 @@ public class EvalFilter extends GroovyValueFilter {
* This contains a list of all the allowed classes
*/
private static final Class<?>[] ALLOWED_TYPES_LIST = {
Math.class,
String.class,

Boolean.class,
Expand Down Expand Up @@ -112,9 +115,8 @@ public class EvalFilter extends GroovyValueFilter {
*/
@Override
public final Object filter(Object o) {
if (o == null || ALLOWED_TYPES.contains(o.getClass()))
if (o==null || ALLOWED_TYPES.contains(o.getClass()) )
return o;

//Return delegates for the objects, if they get access to the actual classes in some way they will get blocked
//because the class is not whitelisted
if(o instanceof JDA)
Expand All @@ -125,7 +127,7 @@ public final Object filter(Object o) {
return new GuildDelegate((Guild) o);
////////////////////////////////////////////
if(o instanceof Script)
return o;
return new ScriptDelegate((Script) o);
if (o instanceof Closure)
throw new SecurityException("Closures are not allowed.");
throw new VRCubeException("Class not allowed: " + o.getClass().getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@
import ml.duncte123.skybot.utils.Settings;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.*;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
import okhttp3.OkHttpClient;
import okhttp3.Request;
Expand Down Expand Up @@ -76,7 +79,7 @@ public boolean contains(Object o) {
*/
protected static void reloadUpvoted() {
try {
String token = AirUtils.config.getString("apis.discordbots_userToken");
String token = AirUtils.config.getString("apis.discordbots_userToken", "");

if (token == null) {
AirUtils.logger.warn("Discord Bots token not found");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Skybot, a multipurpose discord bot
* Copyright (C) 2017 Duncan "duncte123" Sterken & Ramid "ramidzkh" Khan & Sanduhr32
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package ml.duncte123.skybot.objects.delegate;

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

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

public class ScriptDelegate extends Script {

public ScriptDelegate(Script s) {
super(s.getBinding());
}

@Override
public Object run() {
return "I'm a bot, I can't run.";
}

@Override
public void println() {
throw new VRCubeException("Hey, i like to keep my console clean");
}

@Override
public void print(Object value) {
throw new VRCubeException("Hey, i like to keep my console clean");
}

@Override
public void println(Object value) {
throw new VRCubeException("Hey, i like to keep my console clean");
}

@Override
public void printf(String format, Object value) {
throw new VRCubeException("Hey, i like to keep my console clean");
}

@Override
public void printf(String format, Object[] values) {
throw new VRCubeException("Hey, i like to keep my console clean");
}

@Override
public Object evaluate(String expression) throws CompilationFailedException {
throw new VRCubeException("Erm, no?");
}

@Override
public Object evaluate(File file) throws CompilationFailedException, IOException {
throw new VRCubeException("Erm, no?");
}

@Override
public void run(File file, String[] arguments) throws CompilationFailedException, IOException {
throw new VRCubeException("Erm, no?");
}
}
24 changes: 11 additions & 13 deletions src/main/java/ml/duncte123/skybot/utils/AirUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,19 @@
import java.net.URL;
import java.sql.*;
import java.util.*;
import java.util.regex.Pattern;

public class AirUtils {

/**
* This is our config file
*/
public static Config config = new ConfigUtils().loadConfig();
/**
* The {@link WAEngine engine} to query Wolfram|Alpha
* This has to be loadded before the commands are loaded
*/
public static final WAEngine alphaEngine = getWolframEngine();
/**
* This will hold the command setup and the registered commands
*/
Expand All @@ -56,10 +62,6 @@ public class AirUtils {
* We are using slf4j to log things to the console
*/
public static Logger logger = LoggerFactory.getLogger(Settings.defaultName);
/**
* The {@link WAEngine engine} to query Wolfram|Alpha
*/
public static final WAEngine alphaEngine = getWolframEngine();
/**
* This holds the value if we should use a non-SQLite database
*/
Expand Down Expand Up @@ -227,23 +229,19 @@ public static void checkUnbans(ShardManager jda) {
}
}
}


public static final Pattern URL_REGEX = Pattern.compile("[-a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&\\/\\/=]*)");

/**
* This will validate a link
*
* @param url The thing to check
* @return true or false depending on if the url is valid
*/
public static boolean isURL(String url) {
try {
URL u = new URL(url);
u.openConnection();
return true;
} catch (IOException e) {
return false;
}
return URL_REGEX.matcher(url).find();
}

/**
* This will check if the number that we are trying to parse is an int
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ml/duncte123/skybot/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class Settings {
/**
* The icon url for the embeds
*/
public static final String defaultIcon = "https://dshelmondgames.ml/favicon";
public static final String defaultIcon = "https://bot.duncte123.me/img/favicon.png";
/**
* The colour of the bar that your embed has
*/
Expand Down
Loading

0 comments on commit 8299478

Please sign in to comment.