eq2emubot.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. use Discord\Discord;
  3. use Discord\Parts\Channel\Message;
  4. //use Discord\Parts\User\User;
  5. use React\EventLoop\Factory;
  6. //for remote script
  7. use Psr\Http\Message\ResponseInterface;
  8. use Discord\WebSockets\Intents;
  9. use Discord\WebSockets\Event;
  10. use React\Http\Browser;
  11. require __DIR__ . "/vendor/autoload.php";
  12. require_once __DIR__ . "/eq2emubot-functions.php";
  13. require_once __DIR__ . "/options.php";
  14. $loop = Factory::create();
  15. $token = BOTTOKEN; // SEE OPTIONS.PHP FOR DEFINE
  16. $dns = BOTDNS; // SEE OPTIONS.PHP FOR DEFINE
  17. //for http stuff
  18. //$browser = new Browser($loop);
  19. $discord = new Discord([
  20. "token" => $token,
  21. "loop" => $loop,
  22. "loadAllMembers" => true,
  23. "dnsConfig" => $dns,
  24. "intents" =>
  25. Intents::getDefaultIntents() |
  26. Intents::GUILD_MEMBERS |
  27. Intents::MESSAGE_CONTENT,
  28. ]);
  29. //for browser stuff add it becomes
  30. //$discord->on('message', function (Message $message, Discord $discord) use ($browser) {
  31. $discord->on("message", function (Message $message, Discord $discord) {
  32. //setup global vars
  33. $idforadmin = ADMINID;
  34. $adminuser = ADMINNAME;
  35. //setup admin
  36. $isadmin = isadmin($message->author->username, $message->user_id);
  37. //ignore stuff from ourself, so we dont loop spam.
  38. if ($message->author->bot) {
  39. return;
  40. }
  41. //////////////////////////// BOT COMMANDS START
  42. $command = "!help";
  43. $command2 = "!8ball";
  44. $command3 = "!links";
  45. $command4 = "!team";
  46. $command5 = "!online";
  47. //////////////////////////// BOT COMMANDS END
  48. /////////////////////////// COMMAND HANDLERS START
  49. //help
  50. if (preg_match("/{$command}/i", $message->content)) {
  51. $msg =
  52. "```ini\n[Devn00bs Zeklabs Bot 1.0 Public]\n[!help - You are here.]\n[!8ball <question> - Shake the magic 8ball.]\n[!links - Display links related to the project]\n[!team - Lists the development team members]```";
  53. $message->reply($msg);
  54. if ($isadmin == 1) {
  55. //used to show admin commands. below is 100% example taken from Zeklabs bot. You should customize as you add functions
  56. $msg2 =
  57. "```css\n[Devbots ADMIN Commands]\n[!movechar <charname> <zoneshortname> - Moves character to selected zone.]\n[!btlog <world/login> - View last backtrace of type listed.]\n[!asanlog <world/login> - View last asan log of type listed.]\n[!systemstats - View server stats.]\n[!online - View Online Users]```";
  58. $message->reply($msg2);
  59. }
  60. return;
  61. }
  62. if (preg_match("/{$command2}/i", $message->content)) {
  63. $cont = $message["content"];
  64. $question = str_replace("!8ball", "", $cont);
  65. $pieces = explode(" ", $cont);
  66. $reset = $pieces[1];
  67. if (!$reset) {
  68. $msg = "\nPlease enter a question!";
  69. $message->reply($msg);
  70. return;
  71. }
  72. $answer = ball($question);
  73. $msg = "\n " . $answer . " ";
  74. $message->reply($msg);
  75. return;
  76. }
  77. if (preg_match("/{$command3}/i", $message->content)) {
  78. $msg =
  79. "\nHere are some useful links relating to our project:\nZeklabs Website: https://www.zeklabs.com/\nSource (git): https://git.eq2emu.com/devn00b/EQ2EMu\nPlay on Our Servers: https://eq2emu.com/playontest.html\nRun Your Own Server: https://eq2emu.com/installeq2emu.html\nWiki: https://wiki.eq2emu.com/\nDiscord-PHP (Documentation): https://discord-php.github.io/DiscordPHP/";
  80. $message->reply($msg);
  81. return;
  82. }
  83. if (preg_match("/{$command4}/i", $message->content)) {
  84. $msg =
  85. "```\nWe currently split development into two teams, Code and Content. Team Members Include:\nCode Team:\nDevn00b (Team Lead).\nImage (Developer/QC).\n\nContent Team:\nCynnar (Project Lead).\nNeatz09 (Content Team Lead).\nContent Developers: Dorbin, LordPazuzu, Neveruary, Premerio15.\n\nContent Tooling:\nTheFoof (Tooling Lead)\nEmemJR (Developer)\nSplashsky (Developer)\n\nPast/Inactive Developers of note:\nFounding Members: LethalEncounter, JohnAdams\nPast Project Developers Include: Jabantiz, Xinux, Scatman, Scribbles\n\n...And Many Many More.```";
  86. $message->reply($msg);
  87. return;
  88. }
  89. //example command that uses mysql to interact as well as functions from eq2emubot-functions.php
  90. if (preg_match("/{$command5}/i", $message->content)) {
  91. $isadmin = isadmin($message->author->username, $message->user_id);
  92. $link = mysqli_connect(MYSQLHOST, MYSQLUSER, MYSQLPASS, MYSQLDB);
  93. $sql_count = "SELECT count(*) from characters where is_online=1";
  94. $count = $link->query($sql_count);
  95. $row = mysqli_fetch_row($count);
  96. $count2 = $row[0];
  97. if ($count2 == 0) {
  98. $msg = "\nThere are no players currently online.";
  99. $message->reply($msg);
  100. mysqli_close($link);
  101. return;
  102. }
  103. $msg = onlineusers($isadmin);
  104. $msg .= "```";
  105. $msg .= "Total Online " . $count2;
  106. mysqli_close($link);
  107. $message->reply($msg);
  108. }
  109. /////////////////////////// COMMAND HANDLERS END
  110. });
  111. $discord->run();
  112. ?>