XeDev_Legitz

Untitled

Oct 4th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. package me.legitzx.bot.mclisteners;
  2.  
  3. import me.legitzx.bot.Info;
  4. import net.dv8tion.jda.core.entities.TextChannel;
  5. import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
  6. import net.dv8tion.jda.core.hooks.ListenerAdapter;
  7. import java.io.*;
  8. import java.io.File;
  9. import java.io.IOException;
  10.  
  11.  
  12. public class BankListener extends ListenerAdapter {
  13. public static String str;
  14. public static int counter = 0;
  15. public String fileName = "";
  16.  
  17. public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
  18. String[] args = event.getMessage().getContentRaw().split(" ");
  19.  
  20. if (event.getMessage().getAuthor().isBot()) return;
  21.  
  22. if (args[0].equalsIgnoreCase(Info.PREFIX + "setup")) {
  23. //readTextFileUsingScanner(fileName, event.getGuild().getTextChannelById("497238046031216651"));
  24. try {
  25. File file = new File(fileName);
  26. System.out.println(file.getAbsolutePath());
  27. if (file.exists() && file.canRead()) {
  28. long fileLength = file.length();
  29. readFile(file, 0L, event.getChannel());
  30. while (true) {
  31.  
  32. if (fileLength < file.length()) {
  33. readFile(file, fileLength, event.getChannel());
  34. fileLength = file.length();
  35. }
  36. }
  37. }
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42.  
  43. }
  44.  
  45. public static void readFile(File file, Long fileLength, TextChannel channel) throws IOException {
  46. String line = null;
  47.  
  48. BufferedReader in = new BufferedReader(new java.io.FileReader(file));
  49. in.skip(fileLength);
  50. while ((line = in.readLine()) != null) {
  51. System.out.println(line);
  52. channel.sendMessage("`" + line + "`").queue();
  53. }
  54. in.close();
  55. }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment