Advertisement
Guest User

Untitled

a guest
Jan 30th, 2019
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. //SuccessBot by Kinsler22
  2.  
  3. const botconfig = require("./botconfig.json");
  4. const Discord = require("discord.js");
  5. const fs = require("fs");
  6. const mysql = require("mysql")
  7. const gf = require('../SuccessBot/globalFunctions.js');
  8. const schedule = require('node-schedule');
  9.  
  10. const bot = new Discord.Client({disableEveryone: true});
  11. bot.commands = new Discord.Collection();
  12.  
  13. fs.readdir("./commands/", (err, files) => {
  14. if (err) console.error(err);
  15.  
  16. let jsfiles = files.filter(f => f.split(".").pop() === "js");
  17. if (jsfiles.length <= 0){
  18. console.log("No commands to load")
  19. return;
  20. }
  21.  
  22. jsfiles.forEach((f,i) => {
  23. let props = require(`./commands/${f}`)
  24. bot.commands.set(props.help.name, props);
  25. });
  26.  
  27. });
  28.  
  29. const con = mysql.createConnection({
  30. host: 'Don't',
  31. user: 'Steal',
  32. password: 'My',
  33. database: 'Database',
  34.  
  35. });
  36.  
  37. con.connect((err) => {
  38. if(err){
  39. console.log('Error connecting to Db');
  40. console.log(err)
  41. return;
  42. }
  43. console.log('Connection established');
  44. });
  45.  
  46.  
  47. var checkForVerification = schedule.scheduleJob('*/1 * * * *', async message => {
  48. con.query(`SELECT * FROM statsTable WHERE verification != "_" && verification != "Verified" && discordUser = "_"`, (err,rows) => {
  49. if (err) throw err;
  50. if (rows < 1) return
  51. let count = 0
  52. while (count < rows.length){
  53. let guild = bot.channels.get(<THIS IS WHERE YOUR CHANNEL ID GOES>)
  54. console.log(rows[count].discordUser)
  55. let user = guild.members.get(`${rows[count].discordID}`)
  56. user.send(`Type !verify ${rows[count].verification} in chat if you want to link your Success stats from your twitch account ${rows[count].twitchUsername} with your Discord account. Note: this is permenant and codes expire at 2 AM EST every day`)
  57. count += 1
  58. }
  59. });
  60. });
  61.  
  62. bot.on("ready", async () => {
  63. console.log(`${bot.user.username} is online!`);
  64. bot.user.setActivity("YOU 0.0", {type: "WATCHING"});
  65. });
  66.  
  67. bot.on("guildMemberAdd", async member => {
  68. console.log("goes into function")
  69. let welcomechannel = member.guild.channels.find(`name`, "đź‘…welcome")
  70. welcomechannel.send(`${member} joined the discord. Have a great time :D`)
  71. });
  72.  
  73. bot.on("guildMemberRemove", async member => {
  74. let welcomechannel = member.guild.channels.find(`name`, "đź‘…welcome")
  75. welcomechannel.send(`${member} has left the discord. They may or may not be missed :sob:`)
  76. });
  77.  
  78. bot.on("message", async message => {
  79. if (message.author.bot) return;
  80. if (message.channel.type === "dm") return;
  81.  
  82. let prefix = botconfig.index;
  83.  
  84. if (!message.content.startsWith(prefix)){
  85. gf.messageXpGain(bot, message, con);
  86. return;
  87. }
  88.  
  89. let messageArray = message.content.split(" ");
  90. let cmd = messageArray[0];
  91. let args = messageArray.slice(1);
  92.  
  93. let command = bot.commands.get(cmd.slice(prefix.length))
  94. if (command) command.run(bot, message, args, con);
  95.  
  96. if (cmd === `${prefix}hello`){
  97. return message.channel.send("Hello!");
  98. }
  99. });
  100.  
  101.  
  102. bot.login(botconfig.token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement