TheQuack45

Java code; using jReddit, PircBot, and JSON-Simple

Oct 10th, 2014
540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. public static boolean executePost(String channel, String sender, String message) {
  2.         String[] messageArray = message.split(" ");
  3.        
  4.         if (messageArray[0].equals("!hypeBot")) {
  5.             HypeBot bot = HypeBotMain.getHypeBot();
  6.             if (messageArray[1].equals("kill")) {
  7.                 if (checkSender(sender)) {
  8.                     kill(channel, sender);
  9.                 } else {
  10.                     bot.sendMessage(channel, "You don't have permission to do that, " + sender + "!");
  11.                 }
  12.             } else if (messageArray[1].equals("hello")) {
  13.                 bot.sendMessage(channel, "Hello " + sender);
  14.             } else if (messageArray[1].equals("edit")) {
  15.                 String fullname = messageArray[2];
  16.                 String commentOrSelf = messageArray[3];
  17.                 String text = messageArray[4];
  18.                 String subreddit = messageArray[5];
  19.                
  20.                 SubmitActions redditUserSubmitActions = HypeBotMain.getRedditUserSubmitActions();
  21.                 if (commentOrSelf.equals("self")) {
  22.                     redditUserSubmitActions.editSelfPost(fullname, text, subreddit);
  23.                 } else {
  24.                     redditUserSubmitActions.editComment(fullname, text, subreddit);
  25.                 }
  26.             } else if (messageArray[1].equals("hype")) {
  27.                 bot.sendMessage(channel, "HYPE!");
  28.             } else if (messageArray[1].equals("getpost")) {
  29.                 SubmitActions redditUserSubmitActions = HypeBotMain.getRedditUserSubmitActions();
  30.                 String type = messageArray[2];
  31.                 String id = messageArray[3];
  32.                 Response result = null;
  33.                
  34.                 if (type.equals("self")) {
  35.                     result = redditUserSubmitActions.getInfoSelfPost(id, "castawaymattbrush");
  36.                 } else if (type.equals("comment")) {
  37.                     result = redditUserSubmitActions.getInfoComment(id, "castawaymattbrush");
  38.                 }
  39.                
  40.                 bot.sendMessage(channel, result.toString());
  41.                 JSONObject resultAsJSON = (JSONObject) result.getResponseObject();
  42.                 try {
  43.                     Thread.sleep(1000);
  44.                 } catch (InterruptedException e) {
  45.                     // TODO Auto-generated catch block
  46.                     e.printStackTrace();
  47.                 }
  48.                 bot.sendMessage(channel, "casted is: " + resultAsJSON.toString());
  49.                 //List<String> resultList = new ArrayList<String>();
  50.                
  51.                 String resultBody = (String) resultAsJSON.get("body");
  52.                 bot.sendMessage(channel, resultBody);
  53.             }
  54.             return true;
  55.         }
  56.         return false;
  57.     }
Add Comment
Please, Sign In to add comment