Merge pull request #484 from BigBotNetwork/master

Gimme
This commit is contained in:
Skidder 2020-05-21 20:41:20 +02:00 committed by GitHub
commit 4dc8934412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 24 deletions

View file

@ -140,7 +140,8 @@ public class Hadder {
new InviteLinkListener(rethink),
new RulesListener(rethink),
new StarboardListener(rethink),
new VoiceLeaveListener(audioManager));
new VoiceLeaveListener(audioManager),
new OwnerMessageListener(config));
try {
shardManager = builder.build();

View file

@ -39,33 +39,14 @@ public class BlacklistCommand implements Command {
} else {
switch (args[0].toLowerCase()) {
case "add":
if (args.length == 3 && e.getMessage().getMentionedUsers().size() == 1) {
RethinkUser u = new RethinkUser(e.getRethink().getObjectByID("user", e.getMessage().getMentionedUsers().get(0).getId()), e.getRethink());
String blacklisted = e.getRethinkUser().getBlacklisted();
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");
u.setBlacklisted(newblacklisted);
e.getTextChannel().sendMessage(
e.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.owner.blacklist.success.add.title", "",
"commands.owner.blacklist.success.add.description", newblacklisted)
.build()).queue();
u.push();
} else e.getHelpCommand().sendHelp(this, e);
break;
case "remove":
if (args.length == 3 && e.getMessage().getMentionedUsers().size() == 1) {
RethinkUser u = new RethinkUser(e.getRethink().getObjectByID("user", e.getMessage().getMentionedUsers().get(0).getId()), e.getRethink());
String blacklisted = e.getRethinkUser().getBlacklisted();
List<String> commands = new ArrayList<>();
if (!"none".equals(blacklisted)) commands.addAll(Arrays.asList(blacklisted.split(",")));
commands.removeAll(Arrays.asList(args[1].split(",")));
if (args[0].toLowerCase().equals("add")) commands.addAll(Arrays.asList(args[1].split(",")));
else commands.removeAll(Arrays.asList(args[1].split(",")));
LinkedHashSet<String> hashSet = new LinkedHashSet<>(commands);
ArrayList<String> commandsWithoutDuplicates = new ArrayList<>(hashSet);
@ -73,8 +54,8 @@ public class BlacklistCommand implements Command {
u.setBlacklisted(newblacklisted);
e.getTextChannel().sendMessage(
e.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.owner.blacklist.success.remove.title", "",
"commands.owner.blacklist.success.remove.description", newblacklisted)
"commands.owner.blacklist.success."+args[0].toLowerCase()+".title", "",
"commands.owner.blacklist.success."+args[0].toLowerCase()+".description", newblacklisted)
.build()).queue();
u.push();
} else e.getHelpCommand().sendHelp(this, e);

View file

@ -0,0 +1,40 @@
/*
* @author Hax / Hax6775 / Schlauer_Hax
*/
package com.bbn.hadder.listener;
import com.bbn.hadder.core.Config;
import com.bbn.hadder.core.Perms;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.json.JSONObject;
import javax.annotation.Nonnull;
public class OwnerMessageListener extends ListenerAdapter {
Config config;
public OwnerMessageListener(Config config) {
this.config = config;
}
@Override
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
if (config.getOwners().contains(event.getAuthor().getIdLong())) {
String emotename = event.getMessage().getContentRaw().split(":")[1];
if (!emotename.contains(" ")) {
Emote[] emotes = event.getJDA().getEmotesByName(emotename, true).toArray(new Emote[0]);
StringBuilder sb = new StringBuilder();
if (emotes.length!=0) {
for (Emote emote : emotes) {
sb.append(emote.getAsMention() + " ");
}
event.getChannel().sendMessage(sb.toString()).queue();
}
}
}
}
}