Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rikoudosenin/c6b96a516e2cf0b6bc84e8f6de2ce826 to your computer and use it in GitHub Desktop.
Save rikoudosenin/c6b96a516e2cf0b6bc84e8f6de2ce826 to your computer and use it in GitHub Desktop.
package me.sage.tutorial;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
public class BotListener extends ListenerAdapter {
private final Pattern stupidPat = Pattern.compile("\\bi\\s+am\\s+stupid!?\\b");
@Override
public void onMessageReceived(MessageReceivedEvent e) {
if(e.getMessage().getRawContent().equalsIgnoreCase("z!ping")) {
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " Pong!").queue();
}
if(e.getMessage().getRawContent().equalsIgnoreCase("z!info")) {
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " This bot has been created by Sage").queue();
}
if(e.getMessage().getRawContent().startsWith("z!say")) {
if(e.getMessage().getRawContent().equalsIgnoreCase("z!say")){
e.getChannel().sendMessage("What should I say? :thinking:").queue();
} else {
String something = e.getMessage().getRawContent().substring(6);
String anotherone = something.toLowerCase();
Matcher matcher = stupidPat.matcher(anotherone);
if(matcher.find()){
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " is stupid!").queue();
} else if(e.getMessage().getContent().equals("@Sage is stupid")) {
if(e.getMessage().getMentionedUsers().contains(e.getJDA().getUserById(271888508728246274L))) {
e.getChannel().sendMessage("why sage").queue();
} else {
e.getChannel().sendMessage(e.getAuthor().getAsMention() + " you are stupid!").queue();
}
} else {
e.getChannel().sendMessage(something).queue();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment