Skip to content

Commit

Permalink
Merge pull request #3 from TCDG/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
realshaunoneill authored Dec 10, 2016
2 parents 2ec0663 + 089f2be commit d469ad6
Show file tree
Hide file tree
Showing 16 changed files with 465 additions and 240 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ gradle-app.setting
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
*.iml
*.ipr

/discord_servers/
logs/*
build
11 changes: 10 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ before_cache:
before_install:
- chmod +x gradlew

notifications:
webhooks:
urls:
- https://discordapp.com/api/webhooks/255082802662342656/Xb0KE7DpO7tGRNXAvZGANiO-6eLeliPUnsqiT4YYsChA9_ej9wCWDJR1W6gW12NFnt1l
- https://discordapp.com/api/webhooks/255399755075682304/OwKIci7-Hc4P2j80_pYl4Gy5iF7SCZc0K0Idoy6Ebv5OtnWe7h-i1Dn766HJ4CNFAj8L
on_start: always
on_success: always
on_failure: always

script:
- ./gradlew fatJar

cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
- $HOME/.gradle/wrapper/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Master Branch: [![Awesome](https://travis-ci.org/TCDG/LogBot-Discord.svg?bra

## Installation

1. Right now all you need to do is run the jar passing it one argument, the discord token. It will start up and create all the files needed in its run directory.
1. Right now all you need to do is run the jar, to which the bot will create its config.json, then stop. Insert your Bot Token and Maintainer ID, and re-run the jar! It will start up and create all the files needed in its run directory.

## Contributing

Expand All @@ -22,7 +22,7 @@ I created this because I wanted to test with multi-server bots but taught of a f
## Credits

Author: XeliteXirish (www.xelitexirish.com)
Maintainer: KingDGrizzel
Maintainer: KingDGrizzle

## License
Everything in this repo is BSD style license unless otherwise specified.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repositories {
jcenter()
}

version = "1.3.0"
version = "1.4.0"
//create a single Jar with all dependencies (just change the MainClass)
task fatJar(type: Jar) {
manifest {
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/com/xelitexirish/logbot/LogBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.TextChannel;
import com.xelitexirish.logbot.commands.GetCommand;
import com.xelitexirish.logbot.commands.HelpCommand;
import com.xelitexirish.logbot.commands.ICommand;
import com.xelitexirish.logbot.commands.HelpCommand;
import com.xelitexirish.logbot.commands.PurgeCommand;
import com.xelitexirish.logbot.commands.StatusCommand;
import com.xelitexirish.logbot.commands.VIPCommand;
Expand All @@ -41,11 +41,9 @@ public static void main(String[] args) {
try {
jda = new JDABuilder(AccountType.BOT).setToken(DISCORD_TOKEN).setAutoReconnect(true).addListener(new BotListener()).buildBlocking();
} catch (Exception e) {
//e.printStackTrace();
BotLogger.error("Please open config.json and insert your token and Maintainer ID and try again!");
System.exit(0);
}

registerCommands();
handlePlayingMessage();

Expand All @@ -54,18 +52,17 @@ public static void main(String[] args) {

private static void registerCommands() {
commands.put("vip", new VIPCommand());
commands.put("help", new HelpCommand());
commands.put("get", new GetCommand());
commands.put("status", new StatusCommand());
commands.put("purge", new PurgeCommand());
commands.put("help", new HelpCommand());
}

private static void handlePlayingMessage() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
int i;
String[] messages = {"Currently logging: " + jda.getUsers().size() + " members!", "I'm currently logging " + jda.getGuilds().size() + " servers!"};
jda.getPresence().setGame(Game.of(messages[new Random().nextInt(messages.length)]));
}
Expand All @@ -75,7 +72,6 @@ public void run() {
/**
* Helper Methods
*/

public static void handleCommand(CommandParser.CommandContainer cmd) {
if (commands.containsKey(cmd.invoke)) {
commands.get(cmd.invoke).action(cmd.args, cmd.event);
Expand Down
60 changes: 36 additions & 24 deletions src/main/java/com/xelitexirish/logbot/commands/GetCommand.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
package com.xelitexirish.logbot.commands;

import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.List;

import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
//import net.dv8tion.jda.core.exceptions.RateLimitedException;
import com.xelitexirish.logbot.handlers.FileHandler;
import com.xelitexirish.logbot.handlers.PermissionHandler;
import com.xelitexirish.logbot.utils.BotLogger;
import com.xelitexirish.logbot.utils.Constants;
import com.xelitexirish.logbot.utils.MessageUtils;

import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

public class GetCommand implements ICommand {

public static final int MAX_LENGTH = 1000;
private final String HELP_MSG = "Returns the log file for the specified channel or user. Usage: get `channel <mentioned channel>` or `user <mentioned user>`";
private final String HELP_MSG = "Returns the log file for the specified channel or user.\n Usage: '/log get channel <mentioned channel>' or '/log get user <mentioned user / users>'";

@Override
public boolean called(String[] args, MessageReceivedEvent event) {
Expand Down Expand Up @@ -67,7 +71,6 @@ private void getChannelLog(String[] args, MessageReceivedEvent event) {
File logFile = FileHandler.getLogFile(event.getGuild(), event.getTextChannel());
MessageBuilder messageBuilder = new MessageBuilder();
messageBuilder.appendString("This is the log file for channel: " + event.getTextChannel().getName());

if (!event.getAuthor().hasPrivateChannel()) {
event.getAuthor().openPrivateChannel().queue(channel -> {
try {
Expand All @@ -86,10 +89,8 @@ private void getChannelLog(String[] args, MessageReceivedEvent event) {
BotLogger.info(event.getAuthor().getName() + " asked for file: " + logFile.getName() + " on server: " + event.getGuild().getName());

} else if (args.length > 1) {

if (args[1].equalsIgnoreCase("all")) {
// get channel all

File[] channelFiles = FileHandler.getAllServerLogFiles(event.getGuild());
if (channelFiles != null) {
if (!event.getAuthor().hasPrivateChannel()) {
Expand Down Expand Up @@ -149,21 +150,32 @@ private void getUserLog(String[] args, MessageReceivedEvent event) {
searchLength = Integer.parseInt(args[args.length - 1]);
} catch (Exception e) {
}
if (!event.getAuthor().hasPrivateChannel()) {
event.getAuthor().openPrivateChannel().queue(channel -> {
channel.sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
});
} else {
event.getAuthor().getPrivateChannel().sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
}
for (User user : logUser) {
File logFile = FileHandler.getTempLogFile(event, user, searchLength);
try {
event.getAuthor().getPrivateChannel().sendFile(logFile, null).queue();
} catch (IOException e) {
e.printStackTrace();
}
BotLogger.info(event.getAuthor().getName() + " asked for file: " + logFile.getName() + " on the server: " + event.getGuild().getName());
if (searchLength == 0) {
EmbedBuilder eb = new EmbedBuilder();
eb.setTitle("Error while running the get command!");
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
eb.setColor(Color.red);
eb.setDescription("The number you have provided is too small! The number must be higher than 0!");
MessageEmbed embed = eb.build();
event.getChannel().sendMessage(embed).queue();
} else {
if (!event.getAuthor().hasPrivateChannel()) {
event.getAuthor().openPrivateChannel().queue(channel -> {
channel.sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
});
} else {
event.getAuthor().getPrivateChannel().sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
}
for (User user : logUser) {
File logFile = FileHandler.getTempLogFile(event, user, searchLength);
try {
event.getAuthor().getPrivateChannel().sendFile(logFile, null).queue();
} catch (IOException e) {
e.printStackTrace();
}
BotLogger.info(event.getAuthor().getName() + " asked for file: " + logFile.getName() + " on the server: " + event.getGuild().getName());
}
}
}
}
104 changes: 67 additions & 37 deletions src/main/java/com/xelitexirish/logbot/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package com.xelitexirish.logbot.commands;

import java.awt.Color;
import com.xelitexirish.logbot.LogBot;
import com.xelitexirish.logbot.utils.Constants;
import com.xelitexirish.logbot.utils.MessageUtils;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.MessageEmbed;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;

public class HelpCommand implements ICommand {

private final String HELP_MSG = "Use '" + Constants.COMMAND_PREFIX + "help <command name>' to view more information about that command!";

GetCommand getCmd = new GetCommand();
PurgeCommand purgeCmd = new PurgeCommand();
VIPCommand vipCmd = new VIPCommand();
StatusCommand statusCmd = new StatusCommand();

@Override
public boolean called(String[] args, MessageReceivedEvent event) {
return true;
Expand All @@ -17,10 +24,25 @@ public boolean called(String[] args, MessageReceivedEvent event) {
@Override
public void action(String[] args, MessageReceivedEvent event) {
if (args.length == 0) {
event.getTextChannel().sendMessage(getHelpMessage()).queue();
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
embedBuilder.setTitle("Description");
embedBuilder.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
embedBuilder.setDescription("Hey I'm LogBot, my author is XeliteXirish! Check his website out by clicking on the XeliteXirish text!");
embedBuilder.setColor(Color.GREEN);
String commands = "";
commands += "All commands must start with " + Constants.COMMAND_PREFIX + " !\n";
commands += "========================================================\n";
commands += " " + getTag() + ": " + help() + "\n";
commands += " " + getCmd.getTag() + ": " + getCmd.help() + "\n";
commands += " " + purgeCmd.getTag() + ": " + purgeCmd.help() + "\n";
commands += " " + vipCmd.getTag() + ": " + vipCmd.help() + "\n";
commands += " " + statusCmd.getTag() + ": " + statusCmd.help();
embedBuilder.addField("Commands", commands, true);
MessageEmbed embed = embedBuilder.build();
event.getTextChannel().sendMessage(embed).queue();
} else {
String helpCommand = args[0];

ICommand command = getCommandFromString(helpCommand);
sendHelpMessage(event, command);
}
Expand All @@ -32,43 +54,51 @@ public String help() {
}

@Override
public void executed(boolean success, MessageReceivedEvent event) {
}
public void executed(boolean success, MessageReceivedEvent event) {}

@Override
public String getTag() {
return "help";
}

private Message getHelpMessage(){
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Hey I'm LogBot, my author is XeliteXirish! Check his website out (www.xelitexirish.com) \n");
stringBuilder.append("To use a command, start it with: " + Constants.COMMAND_PREFIX + "\n\n");
stringBuilder.append("The following commands can be used by the bot: \n");
for (ICommand command : LogBot.commands.values()){
stringBuilder.append("\t" + command.getTag() + ": " + command.help() + "\n");
}

return MessageUtils.wrapStringInCodeBlock(stringBuilder.toString(), "css");
}

private ICommand getCommandFromString(String commandName) {
if (LogBot.commands.containsKey(commandName)){
return LogBot.commands.get(commandName);
}
return null;
}

private static void sendHelpMessage(MessageReceivedEvent event, ICommand command) {
if (command != null) {
if (command.help() != null) {
event.getTextChannel().sendMessage(command.help()).queue();
} else {
event.getTextChannel().sendMessage("Sorry there is no info available for this command, please contact a bot administrator.").queue();
}
} else {
event.getTextChannel().sendMessage("Sorry but that is not a recognised command!").queue();
}
}

private ICommand getCommandFromString(String commandName) {
if (LogBot.commands.containsKey(commandName)){
return LogBot.commands.get(commandName);
} else {
return null;
}
}

private static void sendHelpMessage(MessageReceivedEvent event, ICommand command) {
if (command != null) {
if (command.help() != null) {
EmbedBuilder eb = new EmbedBuilder();
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
eb.setTitle("Here is the help message for the command: " + command.getTag());
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
eb.setDescription("=========================================================\n" + command.help());
eb.setColor(Color.green);
MessageEmbed embed = eb.build();
event.getTextChannel().sendMessage(embed).queue();
} else {
EmbedBuilder eb = new EmbedBuilder();
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
eb.setTitle("Error in getting the help message for the command " + command.getTag() + "!");
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
eb.setDescription("=========================================================\nThere is no information for that command!\n Please contact the bot maintainer for more information!");
eb.setColor(Color.red);
MessageEmbed embed = eb.build();
event.getTextChannel().sendMessage(embed).queue();
}
} else {
EmbedBuilder eb = new EmbedBuilder();
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
eb.setTitle("Error in finding the command you have requested!!");
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
eb.setDescription("=========================================================\nThe command you have requested does not exist!\nPlease run " + Constants.COMMAND_PREFIX + "help to see a list of available commands!");
eb.setColor(Color.red);
MessageEmbed embed = eb.build();
event.getTextChannel().sendMessage(embed).queue();
}
}
}
Loading

0 comments on commit d469ad6

Please sign in to comment.