Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. var Discord = require('discord.io');
  2. var logger = require('winston');
  3. var auth = require('./auth.json');
  4. // Configure logger settings
  5. logger.remove(logger.transports.Console);
  6. logger.add(new logger.transports.Console, {
  7. colorize: true
  8. });
  9. logger.level = 'debug';
  10. // Initialize Discord Bot
  11. var bot = new Discord.Client({
  12. token: auth.token,
  13. autorun: true
  14. });
  15. bot.on('ready', function (evt) {
  16. logger.info('Connected');
  17. logger.info('Logged in as: ');
  18. logger.info(bot.username + ' - (' + bot.id + ')');
  19.  
  20. });
  21. bot.on('message', function (user, userID, channelID, message, evt) {
  22. // Our bot needs to know if it will execute a command
  23. // It will listen for messages that will start with `!`
  24.  
  25. if (message.substring(0, 1, 2) == '!') {
  26. var args = message.substring(1).split(' ');
  27. var cmd = args[0];
  28. var in1 = args[1];}
  29.  
  30. args = args.splice(1);
  31. switch(cmd) {
  32.  
  33.  
  34. // !ping
  35. case 'ping':
  36. bot.sendMessage({
  37. to: channelID,
  38. message: 'Pong!'
  39. });
  40. break;
  41.  
  42.  
  43. // !commands
  44. case 'commands':
  45. bot.sendMessage({
  46. to: channelID,
  47. message: 'The current commands are: ping, commands, random and rps and the current prefix is h.'
  48. });
  49. break;
  50.  
  51.  
  52. // !random
  53. case 'random':
  54. var randomnumber; // setting the randomnumber variable
  55. var upper;
  56. upper = in1 ;
  57. randomnumber = Math.floor(Math.random() * Math.floor(in1));
  58. bot.sendMessage({to: channelID, message: 'Your random number from 1 to ' + in1 + ' is ' + randomnumber});
  59. break;
  60.  
  61.  
  62. // !rps
  63. case 'rps': //if the code is rps
  64. var in2;
  65. rpsrandom = Math.random();
  66. if ( rpsrandom <= 0.33 ) { in2 = 'rock' ;}
  67. if ( rpsrandom >= 0.67 ) {in2 = 'scissors' ;}
  68. else {in2 = 'paper';}
  69. bot.sendMessage({to: channelID, message: in2});
  70. if (in1 == 'r')//if in1 is rock
  71. {
  72. if (in2 == 'paper'){
  73. bot.sendMessage({to: channelID, message: 'You lose!'});
  74. break;
  75. }
  76. if (in2 == 'scissors'){
  77. bot.sendMessage({to: channelID, message: 'You win!'});
  78. break;
  79. }
  80. else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
  81. break;
  82. }
  83. if (in1 == 'p')//if in1 is rock
  84. {
  85. if (in2 == 'scissors'){
  86. bot.sendMessage({to: channelID, message: 'You lose!'});
  87. break;
  88. }
  89. if (in2 == 'rock'){
  90. bot.sendMessage({to: channelID, message: 'You win!'});
  91. break;
  92. }
  93. else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
  94. break;
  95. }
  96. if (in1 == 's')//if in1 is rock
  97. {
  98. if (in2 == 'rock'){
  99. bot.sendMessage({to: channelID, message: 'You lose!'});
  100. break;
  101. }
  102. if (in2 == 'paper'){
  103. bot.sendMessage({to: channelID, message: 'You win!'});
  104. break;
  105. }
  106. else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
  107. break;
  108. }
  109.  
  110. }
  111. break;
  112. // Just add any case commands if you want to..
  113. }
  114. }
  115. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement