Skip to content

Commit

Permalink
Merge pull request #48 from Mazawrath/beanlotteryFix
Browse files Browse the repository at this point in the history
Beanlottery fix
  • Loading branch information
Mazawrath authored Feb 1, 2019
2 parents ab5994c + eb0b315 commit 7e56cf5
Show file tree
Hide file tree
Showing 40 changed files with 383 additions and 134 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ config/

launch.sh

libsentry_agent_windows-x86_64.dll
sentry.properties

# =========================
# Operating System Files
# =========================
19 changes: 14 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.github.jengelman.gradle.plugins.shadow.transformers.Log4j2PluginsCacheFileTransformer

plugins {
id 'com.github.johnrengelman.shadow' version '4.0.3'
}
Expand All @@ -21,8 +23,13 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.4'

compile(
'com.github.Mazawrath.sdcf4j:sdcf4j-core:v1.1.0',
'com.github.Mazawrath.sdcf4j:sdcf4j-javacord:v1.1.0',
'com.github.Mazawrath.sdcf4j:sdcf4j-core:v1.2.0',
'com.github.Mazawrath.sdcf4j:sdcf4j-javacord:v1.2.0',

'org.apache.logging.log4j:log4j-api:2.11.1',
'org.apache.logging.log4j:log4j-core:2.11.1',

'commons-io:commons-io:2.6',

'com.rethinkdb:rethinkdb-driver:2.3.3',

Expand All @@ -32,8 +39,6 @@ dependencies {

'org.apache.commons:commons-lang3:3.8',

'com.github.twitch4j:twitch4j:v0.12.0',

'org.slf4j:slf4j-api:1.7.25',
'org.slf4j:slf4j-simple:1.7.25',

Expand All @@ -54,7 +59,10 @@ dependencies {
'com.google.api-client:google-api-client:1.24.1',

'com.google.cloud:google-cloud-vision:1.55.0',
'com.google.cloud:google-cloud-storage:1.55.0'
'com.google.cloud:google-cloud-storage:1.55.0',

'io.sentry:sentry:1.7.16',
'io.sentry:sentry-log4j2:1.7.16'
)

runtime(
Expand All @@ -71,6 +79,7 @@ shadowJar {
manifest {
attributes 'Main-Class': 'com.mazawrath.beanbot.Main'
}
transform(Log4j2PluginsCacheFileTransformer)
archiveName = "${projectName}-${version}.${extension}"
}

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/mazawrath/beanbot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@
import de.btobastian.sdcf4j.CommandHandler;
import de.btobastian.sdcf4j.handler.JavacordHandler;
//import org.apache.log4j.BasicConfigurator;
import io.sentry.Sentry;
import org.javacord.api.DiscordApi;
import org.javacord.api.DiscordApiBuilder;
import org.javacord.api.util.logging.FallbackLoggerConfiguration;

import static com.rethinkdb.RethinkDB.r;

public class Main {
private static DiscordApi api;

public static void main(String[] args) {
//BasicConfigurator.configure();
// Enable debugging, if no slf4j logger was found
//FallbackLoggerConfiguration.setDebug(false);
Sentry.init();
System.setProperty("log4j2.loggerContextFactory", "org.apache.logging.log4j.core.impl.Log4jContextFactory");

GoogleCloudVision cloudVision = new GoogleCloudVision();
FallbackLoggerConfiguration.setDebug(false);

Connection conn = r.connection().hostname("localhost").port(28015).connect();

Expand All @@ -39,7 +40,6 @@ public static void main(String[] args) {
restServer.start();
Twitch twitch = new Twitch(args[1], args[2], conn);


new DiscordApiBuilder().setToken(args[0]).login().thenAccept(api -> {
System.out.println("You can invite the bot by using the following url: " + api.createBotInvite());

Expand All @@ -52,6 +52,8 @@ public static void main(String[] args) {
// Set the default prefix
cmdHandler.setDefaultPrefix(".");

cmdHandler.getCommands();

// Register commands

// Standard
Expand Down Expand Up @@ -81,6 +83,7 @@ public static void main(String[] args) {
cmdHandler.registerCommand(new AdminRemoveBeanCoinCommand(points));
cmdHandler.registerCommand(new AdminPostMessageCommand());
cmdHandler.registerCommand(new AdminPostHelpCommand(cmdHandler));
cmdHandler.registerCommand(new AdminLookupUser());
cmdHandler.registerCommand(new AdminTwitch(twitch));
// Copypasta
cmdHandler.registerCommand(new Top500Command(points));
Expand All @@ -97,5 +100,4 @@ public static void main(String[] args) {
cmdHandler.registerCommand(new EightBallCommand(points));
});
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.mazawrath.beanbot.commands;

import com.mazawrath.beanbot.utilities.SentryLog;
import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import de.btobastian.sdcf4j.CommandHandler;
import io.sentry.Sentry;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.entity.server.Server;
import org.javacord.api.entity.user.User;

import java.awt.*;

Expand All @@ -23,7 +27,8 @@ public HelpCommand(CommandHandler commandHandler) {
async = true,
showInHelpPage = true
)
public void onCommand(String[] args, ServerTextChannel channel) {
public void onCommand(String[] args, ServerTextChannel channel, User author, Server server) {
SentryLog.addContext(args, author, server);

String prefix = cmdHandler.getDefaultPrefix();

Expand All @@ -33,6 +38,8 @@ public void onCommand(String[] args, ServerTextChannel channel) {
if (args.length == 1) {
buildCommandHelp(channel, prefix, args[0]);
}

Sentry.clearContext();
}

public void buildDefaultHelp(ServerTextChannel channel, String prefix) {
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/mazawrath/beanbot/commands/ReactCommand.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.mazawrath.beanbot.commands;

import com.mazawrath.beanbot.utilities.Points;
import com.mazawrath.beanbot.utilities.SentryLog;
import com.vdurmont.emoji.EmojiParser;
import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import io.sentry.Sentry;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.message.Message;
Expand All @@ -25,16 +27,18 @@ public ReactCommand(Points points) {
privateMessages = false
)

public void onCommand(String[] command, DiscordApi api, ServerTextChannel serverTextChannel, User author, Server server, Message message) {
public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTextChannel, User author, Server server, Message message) {
SentryLog.addContext(args, author, server);

if (points.removePoints(author.getIdAsString(), api.getYourself().getIdAsString(), server.getIdAsString(), Points.COMMAND_COST)) {
Message messsageBefore = message.getMessagesBefore(1).join().first();
message.delete();
for (int i = 0; i < command.length; i++) {
for (int j = 0; j < command[i].length(); j++) {
if (StringUtils.isAlpha(String.valueOf(command[i].toLowerCase().charAt(j))))
messsageBefore.addReaction(EmojiParser.parseToUnicode(":regional_indicator_symbol_" + command[i].toLowerCase().charAt(j) + ":"));
for (int i = 0; i < args.length; i++) {
for (int j = 0; j < args[i].length(); j++) {
if (StringUtils.isAlpha(String.valueOf(args[i].toLowerCase().charAt(j))))
messsageBefore.addReaction(EmojiParser.parseToUnicode(":regional_indicator_symbol_" + args[i].toLowerCase().charAt(j) + ":"));
}
if (command.length == i + 2) {
if (args.length == i + 2) {
if (i == 0) {
messsageBefore.addReaction(EmojiParser.parseToUnicode(":large_blue_circle:"));
} else if (i == 1) {
Expand All @@ -47,5 +51,7 @@ public void onCommand(String[] command, DiscordApi api, ServerTextChannel server
}
} else
serverTextChannel.sendMessage("You do not have enough beanCoin to use this command.");

Sentry.clearContext();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mazawrath.beanbot.commands;

import com.mazawrath.beanbot.utilities.SentryLog;
import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import io.sentry.Sentry;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.message.embed.EmbedBuilder;
Expand All @@ -21,7 +23,9 @@ public class ServerInfoCommand implements CommandExecutor {
privateMessages = false
)

public void onCommand(String command, DiscordApi api, ServerTextChannel serverTextChannel, User author, Server server) {
public void onCommand(ServerTextChannel serverTextChannel, User author, Server server) {
SentryLog.addContext(null, author, server);

Date date = new Date(server.getCreationTimestamp().getEpochSecond() * 1000L);
DateFormat format = new SimpleDateFormat("MM/dd/yyyy KK:mm:ss a");
format.setTimeZone(TimeZone.getTimeZone("EST"));
Expand All @@ -37,5 +41,7 @@ public void onCommand(String command, DiscordApi api, ServerTextChannel serverTe
if (server.getIcon().isPresent())
embed.setThumbnail(server.getIcon().get());
serverTextChannel.sendMessage(embed);

Sentry.clearContext();
}
}
12 changes: 10 additions & 2 deletions src/main/java/com/mazawrath/beanbot/commands/UserInfoCommand.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.mazawrath.beanbot.commands;

import com.mazawrath.beanbot.utilities.Points;
import com.mazawrath.beanbot.utilities.SentryLog;
import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import io.sentry.Sentry;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.message.embed.EmbedBuilder;
Expand All @@ -29,13 +31,18 @@ public UserInfoCommand(Points points) {
)

public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTextChannel, User author, Server server) {
SentryLog.addContext(args, author, server);

final String[] roleList = {""};
final String[] playing = {""};
final String[] userName = new String[1];

if (args.length != 0) {
if (args[0].contains("@")) {
userName[0] = args[0].substring(2, args[0].length() - 1);
if (args[0].contains("!"))
userName[0] = args[0].substring(3, args[0].length() - 1);
else
userName[0] = args[0].substring(2, args[0].length() - 1);
} else if (args[0].contains("#")) {
api.getCachedUserByDiscriminatedNameIgnoreCase(args[0]).ifPresent(user -> userName[0] = user.getIdAsString());
} else {
Expand Down Expand Up @@ -83,8 +90,9 @@ public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTex
.addInlineField("beanCoin Balance", Points.pointsToString(points.getBalance(user.getIdAsString(), server.getIdAsString())))
.setFooter("User ID: " + user.getIdAsString());
serverTextChannel.sendMessage(embed);

});

Sentry.clearContext();
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.mazawrath.beanbot.commands.admin;

import com.mazawrath.beanbot.utilities.Points;
import com.mazawrath.beanbot.utilities.SentryLog;
import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import io.sentry.Sentry;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.server.Server;
Expand All @@ -25,6 +27,8 @@ public AdminAddBeanCoinCommand(Points pointsPassed) {
)

public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTextChannel, User author, Server server) throws ExecutionException, InterruptedException {
SentryLog.addContext(args, author, server);

if (!author.isBotOwner()) {
serverTextChannel.sendMessage("Only " + api.getOwner().get().getDiscriminatedName() + " can use this command.");
return;
Expand All @@ -36,5 +40,7 @@ public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTex
serverTextChannel.sendMessage("Added " + Points.pointsToString(transferPoints) + " to " + args[0] + ".");
} else
serverTextChannel.sendMessage("Invalid amount of beanCoin.");

Sentry.clearContext();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mazawrath.beanbot.commands.admin;

import com.mazawrath.beanbot.utilities.SentryLog;
import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import io.sentry.Sentry;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.server.Server;
Expand All @@ -17,6 +19,8 @@ public class AdminDeleteMessageCommand implements CommandExecutor {
)

public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTextChannel2, User author, Server server) throws ExecutionException, InterruptedException {
SentryLog.addContext(args, author, server);

if (!author.isBotOwner()) {
// There is no better var name than this and if you think otherwise you're wrong.
serverTextChannel2.sendMessage("Only " + api.getOwner().get().getDiscriminatedName() + " can use this command.");
Expand All @@ -25,5 +29,7 @@ public void onCommand(String[] args, DiscordApi api, ServerTextChannel serverTex

serverTextChannel2.sendMessage(args[1] + " deleted.");
server.getTextChannelById(args[0]).ifPresent(serverTextChannel -> serverTextChannel.deleteMessages(args[1]));

Sentry.clearContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.mazawrath.beanbot.utilities.Lottery;
import com.mazawrath.beanbot.utilities.Points;
import com.mazawrath.beanbot.utilities.SentryLog;
import de.btobastian.sdcf4j.Command;
import de.btobastian.sdcf4j.CommandExecutor;
import io.sentry.Sentry;
import org.javacord.api.DiscordApi;
import org.javacord.api.entity.channel.ServerTextChannel;
import org.javacord.api.entity.message.MessageBuilder;
Expand Down Expand Up @@ -31,12 +33,16 @@ public AdminForceLotteryDrawingCommand(Points points, Lottery lottery) {
)

public void onCommand(DiscordApi api, ServerTextChannel serverTextChannel, User author, Server server) throws ExecutionException, InterruptedException {
SentryLog.addContext(null, author, server);

if (!author.isBotOwner() && !server.isOwner(author)) {
// There is no better var name than this and if you think otherwise you're wrong.
serverTextChannel.sendMessage("Only " + api.getOwner().get().getDiscriminatedName() + " or " + server.getOwner().getDisplayName(server) + " can use this command.");
return;
}

lottery.drawNumbers(points, server, api, serverTextChannel);

Sentry.clearContext();
}
}
Loading

0 comments on commit 7e56cf5

Please sign in to comment.