Guest User

Untitled

a guest
Feb 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. import net.dv8tion.jda.core.AccountType;
  2. import net.dv8tion.jda.core.JDABuilder;
  3. import net.dv8tion.jda.core.exceptions.RateLimitedException;
  4. import net.dv8tion.jda.core.hooks.ListenerAdapter;
  5.  
  6. import net.dv8tion.jda.core.JDA;
  7. import net.dv8tion.jda.core.entities.ChannelType;
  8. import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
  9.  
  10. import javax.security.auth.login.LoginException;
  11. import java.nio.file.Files;
  12. import java.nio.file.Paths;
  13.  
  14. public class Main extends ListenerAdapter{
  15.  
  16. public static void main(String[] args) throws LoginException, RateLimitedException, InterruptedException {
  17. JDA jda = new JDABuilder(AccountType.BOT).setToken("token").buildBlocking();
  18. jda.addEventListener(new Main());
  19. }
  20.  
  21. @Override
  22. public void onMessageReceived(MessageReceivedEvent event)
  23. {
  24. if (event.isFromType(ChannelType.PRIVATE)) {
  25. System.out.printf("[PM] %s: %s\n", event.getAuthor().getName(),
  26. event.getMessage().getContentDisplay());
  27. } else {
  28. System.out.printf("[%s][%s] %s: %s\n", event.getGuild().getName(),
  29. event.getTextChannel().getName(), event.getMember().getEffectiveName(),
  30. event.getMessage().getContentDisplay());
  31.  
  32. if(event.getMessage().getContentDisplay().equalsIgnoreCase("ping")) {
  33. event.getTextChannel().sendMessage("pong").complete();
  34. } else if (event.getMessage().getContentDisplay().equalsIgnoreCase("temp")) {
  35. try {
  36. String rawTemp = Files.readAllLines(Paths.get("/sys/class/thermal/thermal_zone0/temp")).get(0);
  37. double temp = Integer.parseInt(rawTemp)/1000D;
  38. event.getTextChannel().sendMessageFormat("%.1fC", temp).complete();
  39. } catch (Exception ex) {
  40. event.getTextChannel().sendMessage("error").complete();
  41. }
  42. }
  43.  
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment