Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Discord = require('discord.io');
- var logger = require('winston');
- var auth = require('./auth.json');
- // Configure logger settings
- logger.remove(logger.transports.Console);
- logger.add(new logger.transports.Console, {
- colorize: true
- });
- logger.level = 'debug';
- // Initialize Discord Bot
- var bot = new Discord.Client({
- token: auth.token,
- autorun: true
- });
- bot.on('ready', function (evt) {
- logger.info('Connected');
- logger.info('Logged in as: ');
- logger.info(bot.username + ' - (' + bot.id + ')');
- });
- bot.on('message', function (user, userID, channelID, message, evt) {
- // Our bot needs to know if it will execute a command
- // It will listen for messages that will start with `!`
- if (message.substring(0, 1, 2) == '!') {
- var args = message.substring(1).split(' ');
- var cmd = args[0];
- var in1 = args[1];}
- args = args.splice(1);
- switch(cmd) {
- // !ping
- case 'ping':
- bot.sendMessage({
- to: channelID,
- message: 'Pong!'
- });
- break;
- // !commands
- case 'commands':
- bot.sendMessage({
- to: channelID,
- message: 'The current commands are: ping, commands, random and rps and the current prefix is h.'
- });
- break;
- // !random
- case 'random':
- var randomnumber; // setting the randomnumber variable
- var upper;
- upper = in1 ;
- randomnumber = Math.floor(Math.random() * Math.floor(in1));
- bot.sendMessage({to: channelID, message: 'Your random number from 1 to ' + in1 + ' is ' + randomnumber});
- break;
- // !rps
- case 'rps': //if the code is rps
- var in2;
- rpsrandom = Math.random();
- if ( rpsrandom <= 0.33 ) { in2 = 'rock' ;}
- if ( rpsrandom >= 0.67 ) {in2 = 'scissors' ;}
- else {in2 = 'paper';}
- bot.sendMessage({to: channelID, message: in2});
- if (in1 == 'r')//if in1 is rock
- {
- if (in2 == 'paper'){
- bot.sendMessage({to: channelID, message: 'You lose!'});
- break;
- }
- if (in2 == 'scissors'){
- bot.sendMessage({to: channelID, message: 'You win!'});
- break;
- }
- else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
- break;
- }
- if (in1 == 'p')//if in1 is rock
- {
- if (in2 == 'scissors'){
- bot.sendMessage({to: channelID, message: 'You lose!'});
- break;
- }
- if (in2 == 'rock'){
- bot.sendMessage({to: channelID, message: 'You win!'});
- break;
- }
- else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
- break;
- }
- if (in1 == 's')//if in1 is rock
- {
- if (in2 == 'rock'){
- bot.sendMessage({to: channelID, message: 'You lose!'});
- break;
- }
- if (in2 == 'paper'){
- bot.sendMessage({to: channelID, message: 'You win!'});
- break;
- }
- else {bot.sendMessage({to: channelID, message: 'It is a tie!'});
- break;
- }
- }
- break;
- // Just add any case commands if you want to..
- }
- }
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement