Advertisement
Guest User

basic.php

a guest
Feb 18th, 2016
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. <?php
  2. session_start();
  3. error_reporting( error_reporting() & ~E_NOTICE );
  4.  
  5. use Discord\Discord;
  6. use Discord\WebSockets\Event;
  7. use Discord\WebSockets\WebSocket;
  8. use Discord\Parts\Guild;
  9. use Discord\Parts\Permissions\ChannelPermission;
  10. use Discord\Parts\Permissions\RolePermission;
  11. use discord\Parts\User\Member;
  12.  
  13. $d=0;
  14. $rawdata=0;
  15.  
  16. include 'INI.class.php';
  17. $ini = new INI('config.ini');
  18.  
  19.  
  20. // Parse config.ini
  21.  
  22. // **** Emoji cheat sheet: http://www.emoji-cheat-sheet.com/ ****
  23.  
  24. // ############## Usefull Code & Commands ###############
  25. // Send a Invite PM
  26. // -------------
  27. // $invite = $channel->createInvite();
  28. // $message->author->sendMessage("Invite: {$invite->invite_url}");
  29. // $message->reply('Invite sent in PM.');
  30. // Includes the Composer autoload file
  31. // ----------------------
  32. //
  33. // Bot Leave voice channel
  34. // -------------
  35. // $bot->voice->leave();
  36. // $message->reply('Leaving voice channel...');
  37. //-----------------------
  38. //
  39. // Send message to channel
  40. // $message->channel->sendMessage("msg")
  41. //
  42. // $message->author->id;
  43.  
  44.  
  45. include 'vendor/autoload.php';
  46.  
  47. // if ($argc < 3) {
  48. // echo "You must pass your Email and Password into the cmdline. Example: php basic.php <email> <password>";
  49. // die(1);
  50. // }
  51.  
  52. $d = $ini->read('config.ini');
  53. if(isset($d['settings']['email']))
  54. {
  55. $_SESSION['email']=$d['settings']['email'];
  56. }
  57.  
  58. if(isset($d['settings']['owner']))
  59. {
  60. $_SESSION['owner']=$d['settings']['owner'];
  61. }
  62.  
  63. if(isset($d['settings']['password']))
  64. {
  65. $_SESSION['password']=$d['settings']['password'];
  66. }
  67.  
  68. if(isset($d['settings']['status']))
  69. {
  70. $_SESSION['status']=$d['settings']['status'];
  71. }
  72. echo "Testing status: " . $_SESSION['status'] . PHP_EOL;
  73. echo "Testing email: " . $_SESSION['email'] . PHP_EOL;
  74. echo "Testing pass: " . $_SESSION['password'] . PHP_EOL;
  75.  
  76. // Init the Discord instance.
  77. $discord = new Discord($_SESSION['email'], $_SESSION['password']);
  78. // $discord = new Discord($d['settings']['email'], $d['settings']['password']);
  79. // Init the WebSocket instance.
  80. $ws = new WebSocket($discord);
  81.  
  82. // We use EventEmitters to emit events. They are pretty much
  83. // identical to the JavaScript/NodeJS implementation.
  84. //
  85. // Here we are waiting for the WebSocket client to parse the READY frame. Once
  86. // it has done that it will run the code in the closure.
  87.  
  88.  
  89.  
  90. $ws->on('ready', function ($discord) use ($ws) {
  91.  
  92. $discord->updatePresence($ws, $_SESSION['status'], false);
  93.  
  94. // In here we can access any of the WebSocket events.
  95. //
  96. // There is a list of event constants that you can
  97. // find here: https://teamreflex.github.io/DiscordPHP/classes/Discord.WebSockets.Event.html
  98. //
  99. // We will echo to the console that the WebSocket is ready.
  100. echo "Discord WebSocket is ready!".PHP_EOL;
  101.  
  102. // Here we will just log all messages.
  103. $ws->on(Event::MESSAGE_CREATE, function ($message, $discord, $newdiscord) use ($ws) {
  104. if(($message->full_channel->guild->name == "Paradox Lounge") || ($message->full_channel->guild->name == "Death Legion"))
  105. {
  106.  
  107. // $message->reply("Your role is " . $message->author->role);
  108.  
  109. $dat = explode("#", $message->content);
  110. $rawdat=$dat[1];
  111.  
  112. if(strpos($message->content, " ") > 0)
  113. {
  114. $dat = explode(" ", $dat[1]);
  115. $rawdat=$dat[0];
  116. }
  117.  
  118.  
  119. // ################## Link protection Removal ###################
  120.  
  121. if((strpos($message->content, ".com") > 0) || (strpos($message->content, ".org") > 0))
  122. {
  123.  
  124. if($message->full_channel->guild->name == "Paradox Lounge") // ## Channel Restrictions
  125. {
  126.  
  127. $den=$message->author->username;
  128.  
  129. $rmmessages = 0;
  130. $channel = $message->channel;
  131. $num = 0;
  132. $channel->message_count = $rmmessages + 1;
  133.  
  134. foreach ($channel->messages as $key => $message) {
  135. try {
  136. $message->delete();
  137. } catch (PartRequestFailedException $e) {
  138. continue;
  139. }
  140. $num++;
  141. }
  142.  
  143. $message->channel->sendMessage(":no_entry_sign: " . $den . " your link was removed due to our policy.");
  144.  
  145. } // End of channel restrictions #######
  146.  
  147. }
  148.  
  149. // ############### end of link protection #####################
  150.  
  151.  
  152. if(isset($dat[1]))
  153. {
  154.  
  155. if(($rawdat == "restart") && ($message->author->username == "Proxy"))
  156. {
  157. // system("cmd cd C:\xampp\htdocs\bot2");
  158. // system("cmd php basic.php");
  159.  
  160.  
  161. // $this->websocket->on('close', function () {
  162. // echo "[Close] WebSocket was closed.\r\n";
  163. $message->channel->sendMessage(":heavy_exclamation_mark: Restarting Bot");
  164. exec('c:\WINDOWS\system32\cmd.exe /c START C:\xampp\htdocs\bot2\Restart.bat');
  165. die;
  166. // });
  167.  
  168.  
  169. }
  170.  
  171. if($rawdat == "mimic")
  172. {
  173. $msg=str_replace("#mimic ", "", $message->content);
  174. $message->channel->sendMessage(":speaker: " . $msg);
  175. }
  176.  
  177. if($rawdat == "afk")
  178. {
  179. $msg=str_replace("#afk ", "", $message->content);
  180. $message->author->sendMessage("AFK Set: " . $msg);
  181. // $ini->data['afk']['data'][] = $message->author . "€" . $msg;
  182. // $ini->write('config.ini');
  183. }
  184.  
  185. if($rawdat == "back")
  186. {
  187. $isafk="";
  188. $afkmsg="";
  189. $_SESSION['isafk']="";
  190. $_SESSION['afkmsg']="";
  191.  
  192. }
  193.  
  194. if($rawdat == "status")
  195. {
  196. try {
  197. // $message->reply("Attempting status change.:: ");
  198. $nerd=str_replace("#status ", "", $message->content);
  199. $discord->updatePresence($ws, $nerd, false);
  200. $ini->data['settings']['status'] = $nerd;
  201.  
  202.  
  203. }
  204. catch(\Exception $e)
  205. {
  206. $message->reply("There was an error running the command. `{$e->getMessage()}`");
  207. }
  208. }
  209.  
  210. if($rawdat == "purge")
  211. {
  212.  
  213. $rmmessages = $dat[1];
  214. $channel = $message->channel;
  215. $num = 0;
  216. $channel->message_count = $rmmessages + 1;
  217.  
  218. foreach ($channel->messages as $key => $message) {
  219. try {
  220. $message->delete();
  221. } catch (PartRequestFailedException $e) {
  222. continue;
  223. }
  224. $num++;
  225. }
  226.  
  227. $message->reply("Flushed {$num} messages.");
  228. }
  229.  
  230. if($rawdat == "info")
  231. {
  232. $message->channel->sendMessage(":boom: **Paradox Bot** \n ``` Created By: Proxy \n Framework: DiscordPHP \n Version 0.0.1b ``` \n https://github.com/teamreflex/DiscordPHP");
  233. }
  234.  
  235. if($rawdat == "kick")
  236. {
  237. $guild = $discord->guilds->get('name', 'Paradox Lounge');
  238. $members = $guild->members; // Returns a collection of members
  239.  
  240. $memberToKick = $members->get('name', 'Gravebot');
  241. $memberToKick->kick();
  242.  
  243. }
  244.  
  245. if($rawdat == "role")
  246. {
  247. $guild = $discord->guilds->first();
  248. $role = $guild->roles->get('name', '@everyone');
  249. $message->channel->sendMessage("Changing roles for {$role} ");
  250.  
  251. }
  252. if($rawdat == "mkchan")
  253. {
  254.  
  255. $guild = $discord->guilds->get('id', '146064483121496064');////
  256.  
  257. $everyone_role = $guild->roles->get('name', '@everyone');
  258.  
  259. $allow = new \Discord\Parts\Permissions\ChannelPermission;
  260. $allow->create_instant_invite = true;
  261. $deny = new \Discord\Parts\Permissions\ChannelPermission;
  262.  
  263. $channel = new \Discord\Parts\Channel\Channel();
  264. $channel->name = 'Testcreate';
  265. $channel->type = 'text';
  266. $channel->guild_id = '146064483121496064';
  267. $channel->save();
  268.  
  269. $channel->setPermissions($everyone_role, $allow, $deny);
  270.  
  271. // $channel->save();
  272. }
  273.  
  274. } // isset end
  275.  
  276.  
  277.  
  278. $reply = $message->timestamp->format('d/m/y H:i:s') . ' - '; // Format the message timestamp.
  279. $reply .= $message->full_channel->guild->name . ' - ';
  280. $reply .= $message->author->username . ' - '; // Add the message author's username onto the string.
  281. $reply .= $message->content; // Add the message content.
  282. echo $reply . PHP_EOL; // Finally, echo the message with a PHP end of line.
  283.  
  284.  
  285. }
  286. // Server name = $message->full_channel->guild->name;
  287.  
  288. });
  289.  
  290. });
  291.  
  292. error_log("You messed up!", 3, "errors.log");
  293.  
  294. // Now we will run the ReactPHP Event Loop!
  295. $ws->run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement