Merge Greg's branch into the master branch #293

Merged
greg6775 merged 5 commits from greg-dev into master 2020-01-01 17:07:10 +01:00
11 changed files with 169 additions and 15 deletions

View file

@ -19,7 +19,8 @@
"DiscordExtremeList": "",
"DiscordBotReviews": "",
"DiscordBots": "",
"BotListSpace": ""
"BotListSpace": "",
"DiscordBots2": ""
},
"Clyde": ""
}

View file

@ -92,13 +92,14 @@ public class Hadder {
new LanguageCommand(),
new ClydeCommand(),
new PlayCommand(),
new StarBoardCommand(),
new StarboardCommand(),
new QueueCommand(),
new InfoCommand(),
new SkipCommand(),
new EditRulesCommand(),
new VolumeCommand(),
new StopCommand()), config, helpCommand);
new StopCommand(),
new BlacklistCommand()), config, helpCommand);
builder.addEventListeners(
new MentionListener(rethink),

View file

@ -133,14 +133,22 @@ public class Rethink {
}
public void insertUser(String id) {
this.insert("user", r.hashMap("id", id).with("prefix", "h.").with("language", "en"));
this.insert("user", r.hashMap("id", id).with("prefix", "h.").with("language", "en").with("blacklisted", "none"));
}
public void setNeededstars(String stars, String guild_id) {
public void setBlackListed(String id, String commands) {
this.update("user", id, "blacklisted", commands);
}
public String getBlackListed(String id) {
return (String) this.get("user", "id", id, "blacklisted");
}
public void setNeededStars(String stars, String guild_id) {
this.update("server", guild_id, "neededstars", stars);
}
public String getNeededstars(String guild_id) {
public String getNeededStars(String guild_id) {
return (String) this.get("server", "id", guild_id, "neededstars");
}
@ -156,8 +164,8 @@ public class Rethink {
return !this.get("server", "id", guild_id, "starboard").equals("");
}
public void insertStarboardMessage(String message_id, String guild_id, String starboardmessageid) {
this.insert("stars", r.hashMap("id", message_id).with("guild", guild_id).with("starboardmsg", starboardmessageid));
public void insertStarboardMessage(String message_id, String guild_id, String starboard_message_id) {
this.insert("stars", r.hashMap("id", message_id).with("guild", guild_id).with("starboardmsg", starboard_message_id));
}
public String getStarboardMessage(String message_id) {

View file

@ -5,7 +5,7 @@ import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.entities.TextChannel;
public class StarBoardCommand implements Command {
public class StarboardCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
@ -29,7 +29,7 @@ public class StarBoardCommand implements Command {
}
if (args.length==2) {
event.getRethink().setNeededstars(args[1], event.getGuild().getId());
event.getRethink().setNeededStars(args[1], event.getGuild().getId());
}
}

View file

@ -0,0 +1,112 @@
package com.bbn.hadder.commands.owner;
/*
* @author Hax / Hax6775 / Schlauer_Hax
*/
import com.bbn.hadder.commands.Command;
import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.core.Perm;
import com.bbn.hadder.core.Perms;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.User;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
@Perms(Perm.BOT_OWNER)
public class BlacklistCommand implements Command {
@Override
public void executed(String[] args, CommandEvent event) {
if (args.length == 0) {
event.getHelpCommand().sendHelp(this, event);
} else {
switch (args[0].toLowerCase()) {
case "add":
if (args.length == 3) {
Member member = event.getMessage().getMentionedMembers().get(0);
String blacklisted = event.getRethink().getBlackListed(member.getId());
List<String> commands = new ArrayList<>();
if (!"none".equals(blacklisted)) commands.addAll(Arrays.asList(blacklisted.split(",")));
commands.addAll(Arrays.asList(args[1].split(",")));
LinkedHashSet<String> hashSet = new LinkedHashSet<>(commands);
ArrayList<String> commandsWithoutDuplicates = new ArrayList<>(hashSet);
String newblacklisted = ((commandsWithoutDuplicates.size()!=0) ? String.join(",", commandsWithoutDuplicates) : "none");
event.getRethink().setBlackListed(member.getId(), newblacklisted);
event.getTextChannel().sendMessage(
event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO)
.setTitle("Removed Blacklisted Commands from User")
.setDescription("Blacklisted commands: "+newblacklisted)
.build()).queue();
}
break;
case "remove":
if (args.length == 3) {
Member member = event.getMessage().getMentionedMembers().get(0);
String blacklisted = event.getRethink().getBlackListed(member.getId());
List<String> commands = new ArrayList<>();
if (!"none".equals(blacklisted)) commands.addAll(Arrays.asList(blacklisted.split(",")));
commands.removeAll(Arrays.asList(args[1].split(",")));
LinkedHashSet<String> hashSet = new LinkedHashSet<>(commands);
ArrayList<String> commandsWithoutDuplicates = new ArrayList<>(hashSet);
String newblacklisted = ((commandsWithoutDuplicates.size()!=0) ? String.join(",", commandsWithoutDuplicates) : "none");
event.getRethink().setBlackListed(member.getId(), newblacklisted);
event.getTextChannel().sendMessage(
event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO)
.setTitle("Removed Blacklisted Commands from User")
.setDescription("Blacklisted commands: "+newblacklisted)
.build()).queue();
}
break;
case "list":
StringBuilder stringBuilder = new StringBuilder();
for (User user : event.getJDA().getUsers()) {
if (!user.getId().equals(event.getJDA().getSelfUser().getId())) {
String blacklisted = event.getRethink().getBlackListed(user.getId());
if (!blacklisted.equals("none")) {
stringBuilder.append(user.getAsTag()).append(" (").append(user.getId()).append(") - ").append(blacklisted).append("\n");
}
}
}
event.getTextChannel().sendMessage(
event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO)
.setTitle("Blacklisted Users:")
.setDescription((stringBuilder.length()!=0) ? ("``" + stringBuilder.toString() + "``") : "No blacklisted Users")
.build()).queue();
break;
default:
event.getHelpCommand().sendHelp(this, event);
break;
}
}
}
@Override
public String[] labels() {
return new String[]{"blacklist"};
}
@Override
public String description() {
return "commands.owner.blacklist.help.description";
}
@Override
public String usage() {
return "add|remove|list command @User";
}
@Override
public String example() {
return "add solo @Skidder";
}
}

View file

@ -48,7 +48,17 @@ public class CommandHandler {
}
}
cmd.executed(args, commandEvent);
boolean run = true;
String blacklisted = rethink.getBlackListed(event.getAuthor().getId());
if (!"none".equals(blacklisted)) {
for (String blacklistedlabel : blacklisted.split(",")) {
if (Arrays.asList(cmd.labels()).contains(blacklistedlabel)) {
run = false;
}
}
}
if (run)
cmd.executed(args, commandEvent);
return;
}
}

View file

@ -143,6 +143,10 @@ public class Config {
return config.getJSONObject("Tokens").getString("BotListSpace");
}
public String getDiscordBots2Token() {
return config.getJSONObject("Tokens").getString("DiscordBots2");
}
public String getClydeName() {
return config.getString("Clyde");
}

View file

@ -43,7 +43,7 @@ public class StarboardListener extends ListenerAdapter {
}
}
if (Integer.parseInt(rethink.getNeededstars(event.getGuild().getId())) <= stars) {
if (Integer.parseInt(rethink.getNeededStars(event.getGuild().getId())) <= stars) {
event.getGuild().getTextChannelById(rethink.getStarboardChannel(event.getGuild().getId()))
.sendMessage(new MessageBuilder()
.setContent("⭐ 1" + " " + event.getTextChannel().getAsMention())
@ -77,7 +77,7 @@ public class StarboardListener extends ListenerAdapter {
.retrieveMessageById(rethink.getStarboardMessage(event.getMessageId())).queue(
msg2 -> {
if (Integer.parseInt(rethink.getNeededstars(event.getGuild().getId())) <= finalStars) {
if (Integer.parseInt(rethink.getNeededStars(event.getGuild().getId())) <= finalStars) {
msg2.editMessage(new MessageBuilder()
.setContent("" + finalStars + " " + event.getTextChannel().getAsMention())
.setEmbed(

View file

@ -28,6 +28,7 @@ public class BotList {
private static String DiscordBotReviews = "https://discordbotreviews.xyz/api/bot/637002314162372639/stats";
private static String DiscordBots = "https://top.gg/api/bots/637002314162372639/stats";
private static String BotListSpace = "https://api.botlist.space/v1/bots/637002314162372639";
private static String DiscordBots2 = "https://discord.bots.gg/api/v1/bots/637002314162372639/stats";
private Config config;
@ -43,6 +44,7 @@ public class BotList {
json.put("guilds", Hadder.shardManager.getGuilds().size());
json.put("users", Hadder.shardManager.getUsers().size());
json.put("shard_count", Hadder.shardManager.getShards().size());
json.put("shardCount", Hadder.shardManager.getShards().size());
RequestBody body = RequestBody.create(MediaType.parse("application/json"), json.toString());
@ -195,6 +197,21 @@ public class BotList {
} catch (IOException e) {
e.printStackTrace();
}
// Discord Bots 2
Request discordbots2 = new Request.Builder()
.url(DiscordBots2)
.post(body)
.addHeader("Authorization", config.getDiscordBots2Token())
.build();
try {
new OkHttpClient().newCall(discordbots2).execute().close();
System.out.println("Successfully posted count to discord.bots.gg!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

View file

@ -36,8 +36,8 @@ public class MessageEditor {
String description, String description_extra, String description_extra_two) {
String language = (this.user!=null) ? rethink.getLanguage(this.user.getId()) : null;
EmbedBuilder eb = this.getDefaultSettings(type);
if (!title.equals("")) eb.setTitle(this.handle(language, title, title_extra, title_extra_two));
if (!description.equals("")) eb.setDescription(this.handle(language, description, description_extra, description_extra_two));
if (!"".equals(title)) eb.setTitle(this.handle(language, title, title_extra, title_extra_two));
if (!"".equals(description)) eb.setDescription(this.handle(language, description, description_extra, description_extra_two));
return eb;
}

View file

@ -247,6 +247,7 @@ commands.owner.shutdown.success.title = Shutdown
commands.owner.shutdown.help.description = Shuts the Bot down
commands.owner.test.success = TEST my friends
commands.owner.test.help.description = Just a little Test Command
commands.owner.blacklist.help.description = Blacklist a user for specific commands
commands.settings.language.success.title = Language set
commands.settings.language.success.description = `%extra%` is your new language now.