LiquidFenrir

modules.php to use with bot

May 18th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.53 KB | None | 0 0
  1. <?php
  2.  
  3. $commands = array(
  4.     "say" => function($info) {
  5.         socket_write($info["socket"], "PRIVMSG ".$info["channel"]." :".$info["msg"]." (".$info["sender"]["nick"].")\r\n");
  6.     },
  7.     "msg" => function($info) {
  8.         $receiver = $info["d"][4];
  9.         unset($info["d"][4]);
  10.         $msg = trim(implode(" ", $info["d"]));
  11.         socket_write($info["socket"], "PRIVMSG $receiver :$msg (sent by ".$info["sender"]["nick"].")\r\n");
  12.     },
  13.     "notice" => function($info) {
  14.         $receiver = $info["d"][4];
  15.         unset($info["d"][4]);
  16.         $msg = trim(implode(" ", $info["d"]));
  17.         socket_write($info["socket"], "NOTICE $receiver :$msg (sent by ".$info["sender"]["nick"].")\r\n");
  18.     },
  19.     "join" => function($info) {
  20.         if (isOwner($info["sender"])) {
  21.             socket_write($info["socket"], "JOIN ".$info["d"][4]."\r\n");
  22.         }
  23.     },
  24.     "nick" => function($info) {
  25.         if (isOwner($info["sender"])) {
  26.             socket_write($info["socket"], "NICK ".$info["d"][4]."\r\n");
  27.         }
  28.     },
  29.     "leave" => function($info) {
  30.         if (isOwner($info["sender"])) {
  31.             socket_write($info["socket"], "PART ".$info["channel"]."\r\n");
  32.         }
  33.     }
  34. );
  35.  
  36. $commands["quote"] = function($info, $quotes) {
  37.     print_r($quotes);
  38.     $action = $info["d"][4];
  39.     if ($action == "add") {
  40.         unset($info["d"][4]);
  41.         $quote = trim(preg_replace('/[\x00-\x1F\x7F]/', '', trim(implode(" ", $info["d"]))));
  42.         if ($quote == "") {
  43.             socket_write($info["socket"], "PRIVMSG ".$info["channel"]." :Error: can't add a blank quote\r\n");
  44.         } else {
  45.             $quotes[] = array(
  46.                 "quote" => $quote,
  47.                 "user" => $info["sender"]["nick"],
  48.                 "time" => date("Y-n-j G:i")
  49.             );
  50.             file_put_contents("./quotes.json", json_encode($quotes));
  51.             socket_write($info["socket"], "PRIVMSG ".$info["channel"]." :Quote added at index ".count($quotes)."\r\n");
  52.         }
  53.     } elseif ($action == "read") {
  54.         $index = ltrim($info["d"][5], '0');
  55.         if ($index > count($quotes) || $index < 1) {
  56.             socket_write($info["socket"], "PRIVMSG ".$info["channel"]." :Error: index given out of bounds. Try with a number between 1 and ".count($quotes)."\r\n");
  57.         } else {
  58.             $quote = $quotes[$index-1];
  59.             socket_write($info["socket"], "PRIVMSG ".$info["channel"]." :Quote #$index added by ".$quote["user"]." at ".$quote["time"]."\r\n");
  60.             socket_write($info["socket"], "PRIVMSG ".$info["channel"]." :".$quote["quote"]."\r\n");
  61.         }
  62.     }
  63.     return $quotes;
  64. };
  65.  
  66. $commands["uno"] = function($info) {
  67.     $topcard_msg = "imabot's turn. Top Card:";
  68.     $msg = trim(preg_replace('/[\x00-\x1F\x7F]/', '',substr($info["message"], 0, 27)));
  69.     if ($msg == $topcard_msg) {
  70.         write("topcard");
  71.     }
  72.     return false;
  73. }
  74. ?>
Advertisement
Add Comment
Please, Sign In to add comment