Created
October 10, 2017 13:48
-
-
Save DRSchlaubi/e82d257cc29beec4333f443d8d73e641 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.schlaubi.schlaubibot.listeners; | |
import net.dv8tion.jda.core.EmbedBuilder; | |
import net.dv8tion.jda.core.entities.Message; | |
import net.dv8tion.jda.core.entities.MessageChannel; | |
import net.dv8tion.jda.core.entities.Role; | |
import net.dv8tion.jda.core.events.message.MessageReceivedEvent; | |
import net.dv8tion.jda.core.hooks.ListenerAdapter; | |
import net.schlaubi.schlaubibot.commands.Command; | |
import net.schlaubi.schlaubibot.core.commandHandler; | |
import java.awt.*; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
public class zekroListener extends ListenerAdapter { | |
private final String[] ROLES = {"307084559303049216","307084714890625024"}; /*Role IDs for admin roles*/ | |
public static HashMap<String, Command> commands = commandHandler.commands; | |
private final String PREFIX = "::"; /*Replace with your command prefix*/ | |
private final String LOGCHANNEL = "364425303088431106"; /* Log channel */ | |
private final String GUILD = "307084334198816769"; | |
@Override | |
public void onMessageReceived(MessageReceivedEvent event) { | |
if(!event.getGuild().getId().equals(GUILD)) | |
return; | |
checkMention(event); | |
String[] args = event.getMessage().getContent().replaceFirst(PREFIX, "").split(" "); | |
if(commands.containsKey(args[0])){ | |
logCommand(args[0], event); | |
} | |
} | |
private void logCommand(String invoke, MessageReceivedEvent event) { | |
MessageChannel channel = event.getGuild().getTextChannelById(LOGCHANNEL); | |
channel.sendMessage(new EmbedBuilder().setColor(Color.cyan).setDescription("Command `" + invoke + "` was executed by **" + event.getAuthor().getName() + "** in channel " + event.getTextChannel().getAsMention()).build()).queue(); | |
} | |
private void checkMention(MessageReceivedEvent event){ | |
Message message = event.getMessage(); | |
if(message.getMentionedUsers().size() > 0){ | |
if (message.getMentionedUsers().get(0).equals(event.getGuild().getSelfMember().getUser())){ | |
for(Role r : event.getMember().getRoles()){ | |
if(Arrays.stream(ROLES).parallel().anyMatch(r.getId()::contains)){ | |
String[] args = event.getMessage().getContent().split(" "); | |
if(args[1].equals("stop")){ | |
event.getMessage().delete().queue(); | |
event.getChannel().sendMessage(new EmbedBuilder().setDescription("BY BYE :wave: :C").build()).queue(); | |
System.exit(0); | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment