Skip to content

Commit d469ad6

Browse files
Merge pull request #3 from TCDG/develop
Develop
2 parents 2ec0663 + 089f2be commit d469ad6

16 files changed

+465
-240
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ gradle-app.setting
206206
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
207207
# gradle/wrapper/gradle-wrapper.properties
208208
*.iml
209+
*.ipr
209210

210211
/discord_servers/
211212
logs/*
213+
build

.travis.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ before_cache:
99
before_install:
1010
- chmod +x gradlew
1111

12+
notifications:
13+
webhooks:
14+
urls:
15+
- https://discordapp.com/api/webhooks/255082802662342656/Xb0KE7DpO7tGRNXAvZGANiO-6eLeliPUnsqiT4YYsChA9_ej9wCWDJR1W6gW12NFnt1l
16+
- https://discordapp.com/api/webhooks/255399755075682304/OwKIci7-Hc4P2j80_pYl4Gy5iF7SCZc0K0Idoy6Ebv5OtnWe7h-i1Dn766HJ4CNFAj8L
17+
on_start: always
18+
on_success: always
19+
on_failure: always
20+
1221
script:
1322
- ./gradlew fatJar
1423

1524
cache:
1625
directories:
1726
- $HOME/.gradle/caches/
18-
- $HOME/.gradle/wrapper/
27+
- $HOME/.gradle/wrapper/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Master Branch: [![Awesome](https://travis-ci.org/TCDG/LogBot-Discord.svg?bra
55

66
## Installation
77

8-
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.
8+
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.
99

1010
## Contributing
1111

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

2424
Author: XeliteXirish (www.xelitexirish.com)
25-
Maintainer: KingDGrizzel
25+
Maintainer: KingDGrizzle
2626

2727
## License
2828
Everything in this repo is BSD style license unless otherwise specified.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repositories {
44
jcenter()
55
}
66

7-
version = "1.3.0"
7+
version = "1.4.0"
88
//create a single Jar with all dependencies (just change the MainClass)
99
task fatJar(type: Jar) {
1010
manifest {

src/main/java/com/xelitexirish/logbot/LogBot.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import net.dv8tion.jda.core.entities.Guild;
1414
import net.dv8tion.jda.core.entities.TextChannel;
1515
import com.xelitexirish.logbot.commands.GetCommand;
16-
import com.xelitexirish.logbot.commands.HelpCommand;
1716
import com.xelitexirish.logbot.commands.ICommand;
17+
import com.xelitexirish.logbot.commands.HelpCommand;
1818
import com.xelitexirish.logbot.commands.PurgeCommand;
1919
import com.xelitexirish.logbot.commands.StatusCommand;
2020
import com.xelitexirish.logbot.commands.VIPCommand;
@@ -41,11 +41,9 @@ public static void main(String[] args) {
4141
try {
4242
jda = new JDABuilder(AccountType.BOT).setToken(DISCORD_TOKEN).setAutoReconnect(true).addListener(new BotListener()).buildBlocking();
4343
} catch (Exception e) {
44-
//e.printStackTrace();
4544
BotLogger.error("Please open config.json and insert your token and Maintainer ID and try again!");
4645
System.exit(0);
4746
}
48-
4947
registerCommands();
5048
handlePlayingMessage();
5149

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

5553
private static void registerCommands() {
5654
commands.put("vip", new VIPCommand());
57-
commands.put("help", new HelpCommand());
5855
commands.put("get", new GetCommand());
5956
commands.put("status", new StatusCommand());
6057
commands.put("purge", new PurgeCommand());
58+
commands.put("help", new HelpCommand());
6159
}
6260

6361
private static void handlePlayingMessage() {
6462
Timer timer = new Timer();
6563
timer.schedule(new TimerTask() {
6664
@Override
6765
public void run() {
68-
int i;
6966
String[] messages = {"Currently logging: " + jda.getUsers().size() + " members!", "I'm currently logging " + jda.getGuilds().size() + " servers!"};
7067
jda.getPresence().setGame(Game.of(messages[new Random().nextInt(messages.length)]));
7168
}
@@ -75,7 +72,6 @@ public void run() {
7572
/**
7673
* Helper Methods
7774
*/
78-
7975
public static void handleCommand(CommandParser.CommandContainer cmd) {
8076
if (commands.containsKey(cmd.invoke)) {
8177
commands.get(cmd.invoke).action(cmd.args, cmd.event);

src/main/java/com/xelitexirish/logbot/commands/GetCommand.java

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
package com.xelitexirish.logbot.commands;
22

3+
import java.awt.Color;
34
import java.io.File;
45
import java.io.IOException;
56
import java.util.List;
67

7-
import net.dv8tion.jda.core.MessageBuilder;
8-
import net.dv8tion.jda.core.entities.TextChannel;
9-
import net.dv8tion.jda.core.entities.User;
10-
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
11-
//import net.dv8tion.jda.core.exceptions.RateLimitedException;
128
import com.xelitexirish.logbot.handlers.FileHandler;
139
import com.xelitexirish.logbot.handlers.PermissionHandler;
1410
import com.xelitexirish.logbot.utils.BotLogger;
11+
import com.xelitexirish.logbot.utils.Constants;
1512
import com.xelitexirish.logbot.utils.MessageUtils;
1613

14+
import net.dv8tion.jda.core.EmbedBuilder;
15+
import net.dv8tion.jda.core.MessageBuilder;
16+
import net.dv8tion.jda.core.entities.MessageEmbed;
17+
import net.dv8tion.jda.core.entities.TextChannel;
18+
import net.dv8tion.jda.core.entities.User;
19+
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
20+
1721
public class GetCommand implements ICommand {
1822

1923
public static final int MAX_LENGTH = 1000;
20-
private final String HELP_MSG = "Returns the log file for the specified channel or user. Usage: get `channel <mentioned channel>` or `user <mentioned user>`";
24+
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>'";
2125

2226
@Override
2327
public boolean called(String[] args, MessageReceivedEvent event) {
@@ -67,7 +71,6 @@ private void getChannelLog(String[] args, MessageReceivedEvent event) {
6771
File logFile = FileHandler.getLogFile(event.getGuild(), event.getTextChannel());
6872
MessageBuilder messageBuilder = new MessageBuilder();
6973
messageBuilder.appendString("This is the log file for channel: " + event.getTextChannel().getName());
70-
7174
if (!event.getAuthor().hasPrivateChannel()) {
7275
event.getAuthor().openPrivateChannel().queue(channel -> {
7376
try {
@@ -86,10 +89,8 @@ private void getChannelLog(String[] args, MessageReceivedEvent event) {
8689
BotLogger.info(event.getAuthor().getName() + " asked for file: " + logFile.getName() + " on server: " + event.getGuild().getName());
8790

8891
} else if (args.length > 1) {
89-
9092
if (args[1].equalsIgnoreCase("all")) {
9193
// get channel all
92-
9394
File[] channelFiles = FileHandler.getAllServerLogFiles(event.getGuild());
9495
if (channelFiles != null) {
9596
if (!event.getAuthor().hasPrivateChannel()) {
@@ -149,21 +150,32 @@ private void getUserLog(String[] args, MessageReceivedEvent event) {
149150
searchLength = Integer.parseInt(args[args.length - 1]);
150151
} catch (Exception e) {
151152
}
152-
if (!event.getAuthor().hasPrivateChannel()) {
153-
event.getAuthor().openPrivateChannel().queue(channel -> {
154-
channel.sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
155-
});
156-
} else {
157-
event.getAuthor().getPrivateChannel().sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
158-
}
159-
for (User user : logUser) {
160-
File logFile = FileHandler.getTempLogFile(event, user, searchLength);
161-
try {
162-
event.getAuthor().getPrivateChannel().sendFile(logFile, null).queue();
163-
} catch (IOException e) {
164-
e.printStackTrace();
165-
}
166-
BotLogger.info(event.getAuthor().getName() + " asked for file: " + logFile.getName() + " on the server: " + event.getGuild().getName());
153+
if (searchLength == 0) {
154+
EmbedBuilder eb = new EmbedBuilder();
155+
eb.setTitle("Error while running the get command!");
156+
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
157+
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
158+
eb.setColor(Color.red);
159+
eb.setDescription("The number you have provided is too small! The number must be higher than 0!");
160+
MessageEmbed embed = eb.build();
161+
event.getChannel().sendMessage(embed).queue();
162+
} else {
163+
if (!event.getAuthor().hasPrivateChannel()) {
164+
event.getAuthor().openPrivateChannel().queue(channel -> {
165+
channel.sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
166+
});
167+
} else {
168+
event.getAuthor().getPrivateChannel().sendMessage("Here are the chat logs for the user you asked for, this may take a long time:").queue();
169+
}
170+
for (User user : logUser) {
171+
File logFile = FileHandler.getTempLogFile(event, user, searchLength);
172+
try {
173+
event.getAuthor().getPrivateChannel().sendFile(logFile, null).queue();
174+
} catch (IOException e) {
175+
e.printStackTrace();
176+
}
177+
BotLogger.info(event.getAuthor().getName() + " asked for file: " + logFile.getName() + " on the server: " + event.getGuild().getName());
178+
}
167179
}
168180
}
169181
}
Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package com.xelitexirish.logbot.commands;
22

3+
import java.awt.Color;
34
import com.xelitexirish.logbot.LogBot;
45
import com.xelitexirish.logbot.utils.Constants;
5-
import com.xelitexirish.logbot.utils.MessageUtils;
6-
import net.dv8tion.jda.core.entities.Message;
6+
import net.dv8tion.jda.core.EmbedBuilder;
7+
import net.dv8tion.jda.core.entities.MessageEmbed;
78
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
89

910
public class HelpCommand implements ICommand {
1011

1112
private final String HELP_MSG = "Use '" + Constants.COMMAND_PREFIX + "help <command name>' to view more information about that command!";
13+
14+
GetCommand getCmd = new GetCommand();
15+
PurgeCommand purgeCmd = new PurgeCommand();
16+
VIPCommand vipCmd = new VIPCommand();
17+
StatusCommand statusCmd = new StatusCommand();
18+
1219
@Override
1320
public boolean called(String[] args, MessageReceivedEvent event) {
1421
return true;
@@ -17,10 +24,25 @@ public boolean called(String[] args, MessageReceivedEvent event) {
1724
@Override
1825
public void action(String[] args, MessageReceivedEvent event) {
1926
if (args.length == 0) {
20-
event.getTextChannel().sendMessage(getHelpMessage()).queue();
27+
EmbedBuilder embedBuilder = new EmbedBuilder();
28+
embedBuilder.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
29+
embedBuilder.setTitle("Description");
30+
embedBuilder.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
31+
embedBuilder.setDescription("Hey I'm LogBot, my author is XeliteXirish! Check his website out by clicking on the XeliteXirish text!");
32+
embedBuilder.setColor(Color.GREEN);
33+
String commands = "";
34+
commands += "All commands must start with " + Constants.COMMAND_PREFIX + " !\n";
35+
commands += "========================================================\n";
36+
commands += " " + getTag() + ": " + help() + "\n";
37+
commands += " " + getCmd.getTag() + ": " + getCmd.help() + "\n";
38+
commands += " " + purgeCmd.getTag() + ": " + purgeCmd.help() + "\n";
39+
commands += " " + vipCmd.getTag() + ": " + vipCmd.help() + "\n";
40+
commands += " " + statusCmd.getTag() + ": " + statusCmd.help();
41+
embedBuilder.addField("Commands", commands, true);
42+
MessageEmbed embed = embedBuilder.build();
43+
event.getTextChannel().sendMessage(embed).queue();
2144
} else {
2245
String helpCommand = args[0];
23-
2446
ICommand command = getCommandFromString(helpCommand);
2547
sendHelpMessage(event, command);
2648
}
@@ -32,43 +54,51 @@ public String help() {
3254
}
3355

3456
@Override
35-
public void executed(boolean success, MessageReceivedEvent event) {
36-
}
57+
public void executed(boolean success, MessageReceivedEvent event) {}
3758

3859
@Override
3960
public String getTag() {
4061
return "help";
4162
}
42-
43-
private Message getHelpMessage(){
44-
StringBuilder stringBuilder = new StringBuilder();
45-
stringBuilder.append("Hey I'm LogBot, my author is XeliteXirish! Check his website out (www.xelitexirish.com) \n");
46-
stringBuilder.append("To use a command, start it with: " + Constants.COMMAND_PREFIX + "\n\n");
47-
stringBuilder.append("The following commands can be used by the bot: \n");
48-
for (ICommand command : LogBot.commands.values()){
49-
stringBuilder.append("\t" + command.getTag() + ": " + command.help() + "\n");
50-
}
51-
52-
return MessageUtils.wrapStringInCodeBlock(stringBuilder.toString(), "css");
53-
}
54-
55-
private ICommand getCommandFromString(String commandName) {
56-
if (LogBot.commands.containsKey(commandName)){
57-
return LogBot.commands.get(commandName);
58-
}
59-
return null;
60-
}
61-
62-
private static void sendHelpMessage(MessageReceivedEvent event, ICommand command) {
63-
if (command != null) {
64-
if (command.help() != null) {
65-
event.getTextChannel().sendMessage(command.help()).queue();
66-
} else {
67-
event.getTextChannel().sendMessage("Sorry there is no info available for this command, please contact a bot administrator.").queue();
68-
}
69-
} else {
70-
event.getTextChannel().sendMessage("Sorry but that is not a recognised command!").queue();
71-
}
72-
}
7363

64+
private ICommand getCommandFromString(String commandName) {
65+
if (LogBot.commands.containsKey(commandName)){
66+
return LogBot.commands.get(commandName);
67+
} else {
68+
return null;
69+
}
70+
}
71+
72+
private static void sendHelpMessage(MessageReceivedEvent event, ICommand command) {
73+
if (command != null) {
74+
if (command.help() != null) {
75+
EmbedBuilder eb = new EmbedBuilder();
76+
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
77+
eb.setTitle("Here is the help message for the command: " + command.getTag());
78+
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
79+
eb.setDescription("=========================================================\n" + command.help());
80+
eb.setColor(Color.green);
81+
MessageEmbed embed = eb.build();
82+
event.getTextChannel().sendMessage(embed).queue();
83+
} else {
84+
EmbedBuilder eb = new EmbedBuilder();
85+
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
86+
eb.setTitle("Error in getting the help message for the command " + command.getTag() + "!");
87+
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
88+
eb.setDescription("=========================================================\nThere is no information for that command!\n Please contact the bot maintainer for more information!");
89+
eb.setColor(Color.red);
90+
MessageEmbed embed = eb.build();
91+
event.getTextChannel().sendMessage(embed).queue();
92+
}
93+
} else {
94+
EmbedBuilder eb = new EmbedBuilder();
95+
eb.setAuthor(Constants.EMBED_AUTHOR, Constants.EMBED_AUTHOR_URL, Constants.EMBED_AUTHOR_IMAGE);
96+
eb.setTitle("Error in finding the command you have requested!!");
97+
eb.setFooter(Constants.EMBED_FOOTER_NAME, Constants.EMBED_FOOTER_IMAGE);
98+
eb.setDescription("=========================================================\nThe command you have requested does not exist!\nPlease run " + Constants.COMMAND_PREFIX + "help to see a list of available commands!");
99+
eb.setColor(Color.red);
100+
MessageEmbed embed = eb.build();
101+
event.getTextChannel().sendMessage(embed).queue();
102+
}
103+
}
74104
}

0 commit comments

Comments
 (0)