Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing #10

Merged
merged 4 commits into from
Mar 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fixes for stupidity v3
  • Loading branch information
Adam committed Mar 12, 2017
commit 4cb448f16a37bae3c0a3f3c312f5733864bdebd8
48 changes: 48 additions & 0 deletions src/main/java/tk/ardentbot/BotCommands/BotInfo/About.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package tk.ardentbot.BotCommands.BotInfo;

import net.dv8tion.jda.core.EmbedBuilder;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.User;
import tk.ardentbot.Core.CommandExecution.Command;
import tk.ardentbot.Core.Translation.Language;
import tk.ardentbot.Main.Ardent;
import tk.ardentbot.Utils.Discord.MessageUtils;
import tk.ardentbot.Utils.Discord.UserUtils;

import static tk.ardentbot.Main.Ardent.ardent;

public class About extends Command {
public About(CommandSettings commandSettings) {
super(commandSettings);
}

@Override
public void noArgs(Guild guild, MessageChannel channel, User user, Message message, String[] args, Language
language) throws Exception {
EmbedBuilder builder = MessageUtils.getDefaultEmbed(guild, user, this);
builder.setAuthor("Ardent About", ardent.url, ardent.bot.getAvatarUrl());
StringBuilder description = new StringBuilder();
description.append("**What's this?**\n\n")
.append("Ardent was a small project started by Adam#9261 in December of 2016 to have some " +
"fun programming and play music.\n\n")
.append("In March, we had our second developer, Akio, join us, and we've been blessed to have had an " +
"amazing community of staff and members, who are listed below.\n\n");
String devs = MessageUtils.listWithCommas(UserUtils.getNamesById(Ardent.developers));
String moderators = MessageUtils.listWithCommas(UserUtils.getNamesById(Ardent.moderators));
String translators = MessageUtils.listWithCommas(UserUtils.getNamesById(Ardent.translators));
String patrons = MessageUtils.listWithCommas(UserUtils.getNamesById(Ardent.patrons));

description.append("**Developers**: *" + devs + "*\n")
.append("**Moderators**: *" + moderators + "*\n")
.append("**Translators**: *" + translators + "*\n")
.append("**Patrons**: *" + patrons + "*");
builder.setDescription(description);
sendEmbed(builder, channel);
}

@Override
public void setupSubcommands() throws Exception {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.dv8tion.jda.core.entities.*;
import tk.ardentbot.Core.CommandExecution.Command;
import tk.ardentbot.Core.CommandExecution.Subcommand;
import tk.ardentbot.Core.Exceptions.BotException;
import tk.ardentbot.Core.Translation.LangFactory;
import tk.ardentbot.Core.Translation.Language;
import tk.ardentbot.Core.Translation.Translation;
Expand All @@ -14,6 +15,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static tk.ardentbot.Main.Ardent.ardent;

Expand Down Expand Up @@ -78,10 +80,17 @@ public void onCall(Guild guild, MessageChannel channel, User user, Message messa
.getIdentifier()).set(guild.getId()).update();
ardent.botLanguageData.set(guild, changeTo.getIdentifier());
sendRetrievedTranslation(channel, "language", changeTo, "changedlanguage");
sendTranslatedMessage(getTranslation("other", language, "mentionedhelp").getTranslation()
.replace("{0}", GuildUtils.getPrefix(guild) + ardent.help.getName
(language)),
channel);
ardent.executorService.schedule(() -> {
try {
sendTranslatedMessage(getTranslation("other", language, "mentionedhelp")
.getTranslation().replace("{0}", GuildUtils.getPrefix(guild) +
ardent.help.getName(language)), channel);
}
catch (Exception e) {
new BotException(e);
}

}, 5, TimeUnit.SECONDS);
}
else sendRetrievedTranslation(channel, "language", language, "invalidlanguage");
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/tk/ardentbot/BotCommands/Music/Music.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public void playlistLoaded(AudioPlaylist playlist) {

@Override
public void noMatches() {
System.out.println("no match");
if (!search) {
loadAndPlay(user, command, language, channel, "ytsearch: " + trackUrl, voiceChannel, true);
}
Expand Down Expand Up @@ -391,7 +390,7 @@ public void onCall(Guild guild, MessageChannel channel, User user, Message messa
sb.append(response.get(2).getTranslation());
}
else {
sb.append("*" + response.get(3).getTranslation() + "*:" + getDuration(trackList));
sb.append("\n*" + response.get(3).getTranslation() + "*: " + getDuration(trackList));
}
sendTranslatedMessage(sb.toString(), channel);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/tk/ardentbot/Main/Ardent.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Ardent {
public static ArrayList<String> translators = new ArrayList<>();

public static void main(String[] args) throws Exception {
ardent = new Instance(false);
ardent = new Instance(true);
SparkServer.setup();
}
}
4 changes: 3 additions & 1 deletion src/main/java/tk/ardentbot/Main/Instance.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,8 @@ public Instance(boolean testingBot) throws Exception {
.BOTADMINISTRATION)));
factory.registerCommand(manage);

factory.registerCommand(getDevHelp);
factory.registerCommand(new About(new BaseCommand.CommandSettings("about", true, true, Category
.BOTINFO)));
factory.registerCommand(new Support(new BaseCommand.CommandSettings("support", true, true, Category
.BOTINFO)));
factory.registerCommand(new Website(new BaseCommand.CommandSettings("website", true, true, Category
Expand All @@ -249,6 +250,7 @@ public Instance(boolean testingBot) throws Exception {
factory.registerCommand(help);
factory.registerCommand(new Stats(new BaseCommand.CommandSettings("stats", true, true, Category
.BOTINFO)));
factory.registerCommand(getDevHelp);

factory.registerCommand(new UD(new BaseCommand.CommandSettings("ud", true, true, Category.FUN)));
factory.registerCommand(new GIF(new BaseCommand.CommandSettings("gif", true, true, Category.FUN)));
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/tk/ardentbot/Utils/Discord/MessageUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import tk.ardentbot.Core.Translation.Language;

import java.awt.*;
import java.util.ArrayList;
import java.util.Random;

public class MessageUtils {
Expand All @@ -25,4 +26,12 @@ public static EmbedBuilder getDefaultEmbed(Guild guild, User author, BaseCommand
return builder;
}

public static String listWithCommas(ArrayList<String> strings) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < strings.size(); i++) {
sb.append(strings.get(i));
if (i < (strings.size() - 1)) sb.append(", ");
}
return sb.toString();
}
}
9 changes: 9 additions & 0 deletions src/main/java/tk/ardentbot/Utils/Discord/UserUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import net.dv8tion.jda.core.entities.User;
import tk.ardentbot.Main.Ardent;

import java.util.ArrayList;

import static tk.ardentbot.Main.Ardent.*;

public class UserUtils {
Expand All @@ -17,4 +19,11 @@ public static boolean hasManageServerOrStaff(Member member) {
return member.hasPermission(Permission.MANAGE_SERVER) || Ardent.developers.contains(member.getUser().getId())
|| Ardent.moderators.contains(member.getUser().getId());
}

public static ArrayList<String> getNamesById(ArrayList<String> ids) {
ArrayList<String> names = new ArrayList<>();
for (String id : ids) names.add(ardent.jda.getUserById(id).getName());
return names;
}

}