Advertisement
Guest User

MyBot.java

a guest
Jan 27th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.90 KB | None | 0 0
  1. import org.jibble.pircbot.*;
  2.  
  3. public class MyBot extends PircBot {
  4.     public MyBot() {
  5.         this.setName("ElectricBot");
  6.     }
  7.    
  8.     public void onMessage(String channel, String sender, String login, String hostname, String message) {
  9.        
  10.         // This command says Hello, Have a Magical Cookie!
  11.         if (message.equalsIgnoreCase("@hello")) {
  12.             sendMessage(channel, "Hello, Have a Magical Cookie!");
  13.         }
  14.         // This tells the bot to login with nickserv, using the specified password for its nick
  15.         if (message.equalsIgnoreCase("@ident")) {
  16.             sendMessage("NickServ", "identify Max3lis2");
  17.             sendMessage(channel, "This bot is now identified and active!");
  18.         }
  19.         // This tells the user the time
  20.         if (message.equalsIgnoreCase("@time")) {
  21.             String time = (new java.util.Date()).toString();
  22.             sendMessage(channel, sender + ": The time is now " + time);
  23.         }
  24.         // This ops the user who sent the command
  25.         if (message.equalsIgnoreCase("@opme")) {
  26.             op(channel, sender);
  27.         }
  28.         // This deops the user who sent the command
  29.         if (message.equalsIgnoreCase("@deopme")) {
  30.             deOp(channel, sender);
  31.         }
  32.         // This tells the bot to disconnect entirely from the network, allowing a safe quit with CTRL + C
  33.         if (message.equalsIgnoreCase("@botdc")) {
  34.             quitServer("Quit Command Run");
  35.         }
  36.         // Bans a user
  37.         if (message.split(" ")[0].equalsIgnoreCase("@ban")) {
  38.             ban(channel, message.split(" ")[1]);
  39.         }
  40.         // Unbans a user
  41.         if (message.split(" ")[0].equalsIgnoreCase("@unban")) {
  42.             unBan(channel, message.split(" ")[1]);
  43.         }
  44.         // Give the user who executed the command voice
  45.         if (message.equalsIgnoreCase("@voiceme")) {
  46.             voice(channel, sender);
  47.         }
  48.         // Remove voice from the user who executed the command
  49.         if (message.equalsIgnoreCase("@devoiceme")) {
  50.             deVoice(channel, sender);
  51.         }
  52.         // Devoice a user
  53.         if (message.split(" ")[0].equalsIgnoreCase("@devoice")) {
  54.             deVoice(channel, message.split(" ")[1]);
  55.         }
  56.         // Voice a user
  57.         if (message.split(" ")[0].equalsIgnoreCase("@voice")) {
  58.             voice(channel, message.split(" ")[1]);
  59.         }
  60.         // Leave the channel in which the command is executed.
  61.         if (message.equalsIgnoreCase("@part")) {
  62.             sendMessage(channel, "Part command executed, Disconnecting from Channel...");
  63.             partChannel(channel, "Check out https://electricgameing.tk !");
  64.         }
  65.         // Send a raw command through the console
  66.         if (message.split(" ")[0].equalsIgnoreCase("@raw")) {
  67.             sendRawLine(message.split(" ")[1]);
  68.             sendMessage(channel, "Success. Check the console.");
  69.         }
  70.         // Give a user Operator in the current channel
  71.         if (message.split(" ")[0].equalsIgnoreCase("@op")) {
  72.             op(channel, message.split(" ")[1]);
  73.         }
  74.         // Remove a users Operator status in the current channel
  75.         if (message.split(" ")[0].equalsIgnoreCase("@deop")) {
  76.             deOp(channel, message.split(" ")[1]);
  77.         }
  78.  
  79. }  
  80.     // This protected void tells the bot that if its invited to a channel, it is to join it
  81.     protected void onInvite(String targetNick, String sourceNick, String sourceLogin, String sourceHostname, String channel) {
  82.         joinChannel(channel);
  83.     }
  84.     protected void voiceCheck(String channel, String nickname, String targetNick, String sourceNick, String sourceLogin, String sourceHostname) {
  85.         public bool hasVoice(String channel, String nickname) {
  86.   User[] users = getUsers(channel);
  87.   for (User user : users) {
  88.     if (user.getNick().equalsIgnoreCase(nickname))
  89.       return user.hasVoice();
  90.   }
  91.   return false;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement