MuniMuniBot

master
Joshua Sigona 4 years ago
parent 9703031e89
commit da387232bd
  1. 8
      DiscordDivaBot/.classpath
  2. BIN
      DiscordDivaBot/munimuni.jar
  3. 72
      DiscordDivaBot/src/sig/DivaBot.java

@ -1,7 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="C:/Users/sigon/git/DiscordDivaBot/DiscordDivaBot/JDA-3.8.0_423-withDependencies.jar"/>
<classpathentry kind="lib" path="C:/Users/sigon/Downloads/JDA-4.2.0_168-withDependencies.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

Binary file not shown.

@ -6,18 +6,17 @@ import java.util.List;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;
import net.dv8tion.jda.core.events.Event;
import net.dv8tion.jda.core.events.message.MessageDeleteEvent;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.hooks.EventListener;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.requests.RestAction;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Emote;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.requests.RestAction;
import sig.utils.FileUtils;
public class DivaBot extends ListenerAdapter{
@ -29,19 +28,10 @@ public class DivaBot extends ListenerAdapter{
String[] fileContents = FileUtils.readFromFile("clientToken.txt");
//System.out.println(fileContents[0]);
token = fileContents[0];
bot = new JDABuilder(token)
.addEventListener(new DivaBot()).build();
JDA bot = JDABuilder.createDefault(token).build();
bot.addEventListener(new DivaBot());
bot.awaitReady();
List<TextChannel> channels = bot.getTextChannelsByName("bot-tests",true);
RestAction<List<Message>> messageHistory = channels.get(0).getHistory().retrievePast(5);
messageHistory.queue(history->
{
for (int i=0;i<history.size();i++) {
System.out.println(history.get(i).getAuthor().getName()+" "+history.get(i).getAuthor().getId());
System.out.println(history.get(i).getContentDisplay());
}
});
DivaBot.bot=bot;
}
//https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/api/hooks/ListenerAdapter.html
@ -54,24 +44,42 @@ public class DivaBot extends ListenerAdapter{
//System.out.println(ev.getAuthor().getIdLong());
if (ValidMessage(ev.getAuthor(),ev.getChannel())) {
ev.getChannel().sendMessage(ev.getAuthor().getName()+" typed '"+ev.getMessage().getContentDisplay()+"'!")
if (ValidMessage(ev.getAuthor(),ev.getChannel(),ev.getMessage().getContentDisplay())) {
/*ev.getChannel().sendMessage(ev.getAuthor().getName()+" typed '"+ev.getMessage().getContentDisplay()+"'!")
.queue();*/
//System.out.println(bot.getEmotes());
ev.getChannel().addReactionById(ev.getMessageIdLong(), ChooseRandomMuniEmote())
.queue();
messageHistory.put(ev.getMessageIdLong(),ev.getMessage());
//messageHistory.put(ev.getMessageIdLong(),ev.getMessage());
}
}
@Override
private Emote ChooseRandomMuniEmote() {
List<Emote> emotes = bot.getEmotes();
List<Emote> muniEmotes = new ArrayList<Emote>();
for (Emote e : emotes) {
if (e.getName().toLowerCase().contains("muni")) {
muniEmotes.add(e);
}
}
return muniEmotes.get((int)(Math.random()*muniEmotes.size()));
}
/*@Override
public void onMessageDelete(MessageDeleteEvent ev) {
if (ValidMessage(null,ev.getChannel())) {
Long messageId = ev.getMessageIdLong();
ev.getChannel().sendMessage("Message was deleted: "+messageHistory.get(messageId).getAuthor().getName()+": "+messageHistory.get(messageId).getContentDisplay())
.queue();
}
}
}*/
public boolean ValidMessage(User author,MessageChannel channel) {
return (author==null||author.getIdLong()!=744693388632391762l)
&&channel.getName().equalsIgnoreCase("bot-tests");
public boolean ValidMessage(User author,MessageChannel channel,String message) {
return (author==null||author.getIdLong()!=809417111859888168l)
&&(channel.getName().equalsIgnoreCase("bot-tests")||
channel.getIdLong()==772923108997857291l/*D4DJcord tiering channel*/||
channel.getName().equalsIgnoreCase(author.getName()))
&&(message.toLowerCase().contains("muni")||
message.toLowerCase().contains("むに"));
}
}

Loading…
Cancel
Save