Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import net.dv8tion.jda.core.AccountType;
- import net.dv8tion.jda.core.JDABuilder;
- import net.dv8tion.jda.core.exceptions.RateLimitedException;
- import net.dv8tion.jda.core.hooks.ListenerAdapter;
- import net.dv8tion.jda.core.JDA;
- import net.dv8tion.jda.core.entities.ChannelType;
- import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
- import javax.security.auth.login.LoginException;
- import java.nio.file.Files;
- import java.nio.file.Paths;
- public class Main extends ListenerAdapter{
- public static void main(String[] args) throws LoginException, RateLimitedException, InterruptedException {
- JDA jda = new JDABuilder(AccountType.BOT).setToken("token").buildBlocking();
- jda.addEventListener(new Main());
- }
- @Override
- public void onMessageReceived(MessageReceivedEvent event)
- {
- if (event.isFromType(ChannelType.PRIVATE)) {
- System.out.printf("[PM] %s: %s\n", event.getAuthor().getName(),
- event.getMessage().getContentDisplay());
- } else {
- System.out.printf("[%s][%s] %s: %s\n", event.getGuild().getName(),
- event.getTextChannel().getName(), event.getMember().getEffectiveName(),
- event.getMessage().getContentDisplay());
- if(event.getMessage().getContentDisplay().equalsIgnoreCase("ping")) {
- event.getTextChannel().sendMessage("pong").complete();
- } else if (event.getMessage().getContentDisplay().equalsIgnoreCase("temp")) {
- try {
- String rawTemp = Files.readAllLines(Paths.get("/sys/class/thermal/thermal_zone0/temp")).get(0);
- double temp = Integer.parseInt(rawTemp)/1000D;
- event.getTextChannel().sendMessageFormat("%.1fC", temp).complete();
- } catch (Exception ex) {
- event.getTextChannel().sendMessage("error").complete();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment