package com.bernard.julianatheme.anathemes; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.List; import com.bernard.julianatheme.EventReciever; import com.bernard.julianatheme.JuLIAnatheme; import com.bernard.julianatheme.JuliAnathemeManager; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; public class StopTalkingAnatheme extends JuLIAnatheme { public static final String NAME = "stopTalking"; static { JuliAnathemeManager.registerAnatheme(NAME, StopTalkingAnatheme.class); } long[] channelsIDs; public StopTalkingAnatheme(Member cible, Member source) { super(cible, source); } @Override public void write(DataOutputStream dos) throws IOException { dos.writeInt(channelsIDs.length); for (long cid : channelsIDs) dos.writeLong(cid); } @Override public void read(DataInputStream dos) throws IOException { channelsIDs = new long[dos.readInt()]; for (int i = 0; i < channelsIDs.length; i++) channelsIDs[i] = dos.readLong(); } @Override public void initialize(String extra, Guild g) throws InvalidAnathemDescriptionException { if (extra == "") { List tCns = g.getTextChannels(); channelsIDs = new long[tCns.size()]; for (int i = 0; i < channelsIDs.length; i++) { channelsIDs[i] = tCns.get(i).getIdLong(); } } else { String[] splitted = extra.split(","); channelsIDs = new long[splitted.length]; for (int i = 0; i < splitted.length; i++) { TextChannel restriction = g.getTextChannelById(splitted[i]); if (restriction == null) throw new InvalidAnathemDescriptionException("stopTalking", "Il n'existe pas de TextChannel d'ID '" + splitted[i] + "' (du moins pas dans ce serveur)"); channelsIDs[i] = restriction.getIdLong(); } } } @Override public String dump() { return "Sur les canaux " + Arrays.toString(channelsIDs); } @EventReciever public void replyEveryMessages(MessageReceivedEvent event) { System.out.println("Retorquage en cours ..."); if (event.getAuthor().getIdLong() == cible.getUser().getIdLong() && Arrays.binarySearch(channelsIDs, event.getChannel().getIdLong()) >= 0) { String counterLine = counterLines[(int) Math.floor((Math.random() * counterLines.length))]; MessageBuilder builder = new MessageBuilder(); builder.append(cible); builder.append(" : "); builder.append(counterLine); event.getChannel().sendMessage(builder.build()).complete(); } } String[] counterLines = { "Mais qu'es-ce qu'il parle, lui ?", "Faites le taire !", "Peut-il fermer son clapet ?", "Si c'est pour dire de la merd#, ca valait pas la peine", "Là on vois bien qu'il est idiot !", "Tu sais que personne ne veut t'écouter", "Mais Arette de parler !!!", "Shut the fuck up !", "https://youtu.be/Vh2je2c45lg", "Mais qui a donné une langue à cette personne, un cerveau aurait été un bon début !", "Tu as de la chance que mes devs m'on interdit de de mute ...", "Ah si tu pouvais fermer ... TA GUEULE !", "https://youtu.be/OoNSPEFDuxo", "Als Maul !!! (C'est plus frappant en allemand)" }; }