Advertisement
Guest User

MP ALL

a guest
Feb 23rd, 2020
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.07 KB | None | 0 0
  1.  
  2. <?php
  3. /*
  4. * Discord bot for maniaplanet
  5. * Display the rank of a player in his continent and other fun commands !
  6. * V 1.1
  7. * Made by Nykho, 22016
  8. * Credit to Kleis Auke#5462 for the help!
  9. * Thx also to Nerpson#1996 and HYPE#4144 for their help too !
  10. */
  11.  
  12. ini_set('memory_limit', '-1'); // REMOVING PHP MEMORY LIMIT
  13.  
  14. include __DIR__ . '/vendor/autoload.php';
  15.  
  16. use Discord\Bot\CommandBot;
  17. use Discord\Discord;
  18. use Discord\Parts\Channel\Channel;
  19. use Discord\Parts\Channel\Message;
  20. use Discord\Voice\VoiceClient;
  21. use Maniaplanet\WebServices;
  22. use Manialib\Formatting\String;
  23.  
  24. $MpBot = new CommandBot([
  25. 'bot-token' => getenv('DISCORD_BOT_TOKEN'),
  26. 'name' => 'MpBot'
  27. ]);
  28. $MpBot->on('ready', function ($config, $discord, CommandBot $MpBot) {
  29.  
  30. $MpBot->getLogger()->addInfo('Bot is running.', [
  31. 'user' => "{$discord->username}#{$discord->discriminator}",
  32. 'prefix' => $config['prefix'],
  33. ]);
  34. $MpBot->getLogger()->addNotice("Connected to " . count($discord->guilds) . " servers");
  35. });
  36.  
  37. $MpBot->addCommand('coin', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  38. $images = ["heads.png", "tails.png"];
  39. $result = $images[rand(0, 1)];
  40.  
  41. $message->channel->sendFile("image/coin/{$result}", $result)->then(function ($response) use ($bot) {
  42. $bot->getLogger()->addInfo("The file was sent!");
  43. })->otherwise(function (\Exception $e) use ($bot) {
  44. $bot->getLogger()->addInfo("There was an error sending the file: {$e->getMessage()}");
  45. });
  46. });
  47. $MpBot->addCommand('rank', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  48. if (count($params) == 1) {
  49. $login = $params[0];
  50. $nickname = ReturnNickname($login);
  51. $rankS = ReturnRank($login,'SMStorm'); //Seeking the rank of the player, function at the bottom of this script
  52. $rankT = ReturnRank($login,'TMStadium'); //Seeking the rank of the player, function at the bottom of this script
  53. if (is_numeric($rankS) && is_numeric($rankT)) {
  54. $message->channel->sendMessage("The rank of $nickname in Storm is : $rankS and the rank in Stadium is : $rankT",false);
  55. }
  56. else {
  57. $message->channel->sendMessage("This login does not exist !",false);
  58. }
  59.  
  60. }
  61. elseif (count($params) == 2) {
  62. $login = $params[0];
  63. $title = $params[1];
  64. $titleId = ReturnTitle($title);
  65. $title = ucfirst(strtolower($title));
  66. $nickname = ReturnNickname($login);
  67. $rank = ReturnRank($login,$titleId); //Seeking the rank of the player, function at the bottom of this script
  68.  
  69. if ($rank != -1) {
  70. if (is_numeric($rank)) {
  71. $message->channel->sendMessage("The rank of $nickname in $title is : $rank",false);
  72. }
  73. else {
  74. $message->channel->sendMessage("This login does not exist !",false);
  75. }
  76. }
  77. else {
  78. $message->channel->sendMessage("This Title does not exist !",false);
  79.  
  80. }
  81. }
  82. else {
  83. $message->reply('incorrect use of !rank ! See **!help** for more information about ;)');
  84. }
  85. });
  86.  
  87. $MpBot->addCommand('help', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  88. $msg = 'Here some help for my commands !
  89. **!rank** (Display the rank of a maniaplanet login). Use : !rank <login> <title> (default title = Storm)
  90. Title usable : Storm, Elite, Royal, Stadium, Canyon, Valley, Combo, Obstacle, Esltm, Galaxy, Rpg, Speedball, Lagoon
  91. Send a PM to Nykho#8970 if you want to add your title pack to the list !
  92. ***Note : login are case sensitive, not the titlepack***
  93. **!kappa** (Display a beautiful face of our lord Kappa.
  94. **!ping** (Guess ? ;) )
  95. **!yo** (An absolutly basic welcome message :)
  96. **!hey** (What\'s up ?)
  97. **!how** (Ask if you\'re doing well :D)
  98. **!coin** (Flip the coin of the discord logo)
  99. **!hylis** (Display a beautiful mixed face between kappa and Hylis (thx xrayjay !)';
  100. $message->reply($msg,false);
  101. });
  102.  
  103. $MpBot->addCommand('yo', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  104. $message->reply("welcome ! Type !help to know what I can do ;)",false);
  105. });
  106.  
  107. $MpBot->addCommand('hey', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  108. $message->channel->sendMessage("What's up ?",false);
  109. });
  110.  
  111. $MpBot->addCommand('kappa', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  112. $message->channel->sendFile('image/kappa.png', 'kappa.png')->then(function ($response) {
  113. echo "The file was sent!";
  114. })->otherwise(function (\Exception $e){
  115. echo "There was an error sending the file: {$e->getMessage()}";
  116. });
  117. //$message->reply("http://bit.do/kappaimg",false); //While the function is broken, using a link to send the kappa
  118. });
  119.  
  120. $MpBot->addCommand('how', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  121. $message->channel->sendMessage("How you're doing ?",false);
  122. });
  123.  
  124. $MpBot->addCommand('ping', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  125. $message->reply('pong!');
  126. });
  127.  
  128. $MpBot->addCommand('hylis', function ($params, Message $message, CommandBot $bot, Discord $discord) {
  129. $message->channel->sendFile("image/hyliskappa.png", $result)->then(function ($response) use ($bot) {
  130. $bot->getLogger()->addInfo("The file was sent!");
  131. })->otherwise(function (\Exception $e) use ($bot) {
  132. $bot->getLogger()->addInfo("There was an error sending the file: {$e->getMessage()}");
  133. });
  134. });
  135.  
  136. $MpBot->start();
  137.  
  138. //////////////////////////////////////////////////////////////////
  139. /////// Function used in this script are placed here /////////////
  140. //////////////////////////////////////////////////////////////////
  141.  
  142. //Return the rank of a given player on a giver title
  143. function ReturnRank($login,$titleId) {
  144. if ($titleId == "Error ! Title not recognized") {
  145. return -1;
  146. }
  147. $username = 'nicolas1001|SMDiscord';
  148. $password = 'ShootmaniaDiscord';
  149. $players = new \Maniaplanet\WebServices\Players($username, $password);
  150. $rankings = new \Maniaplanet\WebServices\Rankings($username, $password);
  151. try {
  152. $player = $players->get($login);
  153. /*$test = json_encode(($rankings->getMultiplayerPlayer($titleId,$login)),true);
  154. $params = explode("u'", $test);
  155. $reconstruction = explode("\"", $params[0]); // To get out the rank :D
  156. $params = $reconstruction;
  157. $nbCase = count($params);
  158. return $params[37];*/
  159.  
  160. $obj = $rankings->getMultiplayerPlayer($titleId,$login);
  161. $rank = $obj->ranks[1]->rank;
  162. return $rank;
  163. }
  164. catch(Exception $e) {
  165. return "Error ! Login incorrect !";
  166. }
  167. }
  168. //Return the title sheme of maniaplanet by giving a title general name
  169. function ReturnTitle($titleId) {
  170. $titleId = ucfirst(strtolower($titleId));
  171. switch ($titleId) {
  172. case "Storm" : return('SMStorm');
  173. case "Lagoon" : return('TMLagoon');
  174. case "Canyon" : return('TMCanyon');
  175. case "Speedball": return ('SpeedBall@steeffeen');
  176. case "Royal" : return('SMStormRoyal@nadeolabs');
  177. case "Stadium" : return('TMStadium');
  178. case "Elite" : return('SMStormElite@nadeolabs');
  179. case "Valley" : return('TMValley');
  180. case "Combo" : return('SMStormCombo@nadeolabs');
  181. case "Siege" : return('SMStormSiege@nadeolabs');
  182. case "Obstacle" : return('obstacle@steeffeen');
  183. case "Esltm" : return('esl_comp@lt_forever');
  184. case "Galaxy" : return('GalaxyTitles@domino54');
  185. case "Rpg" : return('RPG@tmrpg');
  186. case "Tmplus" : return('TMPLUS@redix');
  187. default : return('Error ! Title not recognized');
  188. }
  189. }
  190.  
  191. // Return the nickname in game of a given string login
  192. function ReturnNickname($login){
  193. $username = 'nicolas1001|SMDiscord';
  194. $password = 'ShootmaniaDiscord';
  195. $players = new \Maniaplanet\WebServices\Players($username, $password);
  196. $rankings = new \Maniaplanet\WebServices\Rankings($username, $password);
  197. try {
  198. $player = $players->get($login)->nickname;
  199. $string = new \Manialib\Formatting\String($player);
  200. $nicknameFinal = $string->stripAll();
  201. return $nicknameFinal;
  202. }
  203. catch(Exception $e) {
  204. return "Error ! Login incorrect !";
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement