Skip to content
This repository has been archived by the owner on May 10, 2021. It is now read-only.

Commit

Permalink
Random changes & almost done with MySQL integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystalflxme committed Feb 6, 2020
1 parent 24d7d2d commit a3ab8e9
Show file tree
Hide file tree
Showing 158 changed files with 28,220 additions and 112 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

2 changes: 1 addition & 1 deletion StartBot.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node index.js
node bot.js
pause
2 changes: 1 addition & 1 deletion bot-config.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"ERR_MSG":"Sorry, unknown command!","DEFAULT_UI_COLOR":"0xFF4000","SERVER_POINTS_UI_COLOR":"0xFFBD33","BOT_NAME":"Cylbot","BOT_VERSION":"v1.0.0","BOT_DESCRIPTION":"Cylbot is a unique multi-use Discord bot.","COMMAND_COOLDOWN":1,"POINTS_COOLDOWN":300,"MAX_WORK_AMOUNT":7}
{"ERR_MSG":"Sorry, unknown command!","DEFAULT_UI_COLOR":"0xFF4000","SERVER_POINTS_UI_COLOR":"0x00D2FF","SERVER_POINTS":"Cylbot Xels","SERVER_POINTS_NAME":"Xels","BOT_NAME":"Cylbot","BOT_VERSION":"v1.2.0","BOT_DESCRIPTION":"Cylbot is a unique multi-use Discord bot.","COMMAND_COOLDOWN":1,"POINTS_COOLDOWN":300,"MAX_WORK_AMOUNT":7}
14 changes: 13 additions & 1 deletion index.js → bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Discord = require("discord.js");
const { CommandHandler } = require("djs-commands")
const botSecrets = require("./../bot-secrets.json")
const botConfig = require("./bot-config.json")
const mySQL = require("mysql")
const CH = new CommandHandler({
folder: __dirname + "/commands/",
prefix: [";"]
Expand All @@ -16,13 +17,24 @@ bot.on("message", (message) => {
let cmd = CH.getCommand(command)
if (cmd) {
try {
cmd.run(bot, message, args)
cmd.run(bot, message, args, connection)
} catch(e) {
console.log(e)
}
}
});

var connection = mySQL.createConnection({
host: "localhost",
user: "root",
password: botSecrets.SQLPASS,
database: botSecrets.SQLDB
})
connection.connect(err => {
if (err) throw err
console.log("[STARTUP] Connected to the database!")
})

bot.on("ready", () => {
bot.user.setActivity("for ;commands", {type:"WATCHING"})
console.log(`[STARTUP] ${botConfig.BOT_NAME} ${botConfig.BOT_VERSION} started!`)
Expand Down
47 changes: 33 additions & 14 deletions commands/balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,42 @@ module.exports = class test {
this.usage = ';balance {user}'
}

async run(bot, message, args) {
let points = require("./../points.json")
async run(bot, message, args, connection) {
const botConfig = require("./../bot-config.json")
let findUser = message.guild.member(message.mentions.users.first())
let pointAmt = 0
if (!findUser) {
if (!points[message.author.id]) return message.reply("You don't have any points, silly!")
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.addField("**🌟 Server Points 🌟**",`${message.author} currently has **${points[message.author.id].points}** points!`,false)
message.channel.send(embed);
}
if (findUser) {
if (!points[findUser.id]) return message.reply(`${findUser} doesn't have any points, silly!`)
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.addField("**🌟 Server Points 🌟**",`${findUser} currently has **${points[findUser.id].points}** points!`,false)
message.channel.send(embed);
connection.query(`SELECT * FROM points WHERE id = '${message.author.id}'`, (err, rows) => {
if (err) throw err
if (rows.length < 1) {
let sql = `INSERT INTO points(id, points) VALUES ('${message.author.id}', 0)`
connection.query(sql)
pointAmt = 0
} else {
pointAmt = rows[0].points
}
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${message.author} currently has **${pointAmt}** ${botConfig.SERVER_POINTS_NAME}!`)
message.channel.send(embed);
})
} else if (findUser) {
connection.query(`SELECT * FROM points WHERE id = '${findUser.id}'`, (err, rows) => {
if (err) throw err
if (rows.length < 1) {
let sql = `INSERT INTO points(id, points) VALUES ('${findUser.id}', 0)`
connection.query(sql)
pointAmt = 0
} else {
pointAmt = rows[0].points
}
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${findUser} currently has **${pointAmt}** ${botConfig.SERVER_POINTS_NAME}!`)
message.channel.send(embed);
})
}
}
}
26 changes: 15 additions & 11 deletions commands/coin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ const Discord = require("discord.js");
module.exports = class test {
constructor(){
this.name = 'coin',
this.alias = ['coinbet']
this.alias = ['coin-bet']
this.usage = ';coin {heads or tails} {bet amount}'
}

async run(bot, message, args) {
async run(bot, message, args, connection) {
const fs = require("fs")
let points = require("./../points.json")
const botConfig = require("./../bot-config.json")
if (!points[message.author.id]) return message.reply("You don't have any points to gamble with, silly!")
if (!points[message.author.id]) return message.reply(`You don't have any ${botConfig.SERVER_POINTS_NAME} to gamble with, silly!`)
if (!args[1] === "heads") return message.reply("You must put heads or tails as your bet!")
if (!args[1] === "tails") return message.reply("You must put heads or tails as your bet!")
if (!args[2]) return message.reply("Point amount not found!")
let pointAmount = parseInt(args[2])
if (!Number.isSafeInteger(pointAmount)) return message.reply("Point amount isn't a number or it is too large!")
if (pointAmount === 0) return message.reply("You can't bet zero points, silly!")
if(Math.sign(pointAmount) === -1) return message.reply("You can't bet negative points, silly!")
if (points[message.author.id].points < pointAmount) return message.reply("You don't have enough points for that, silly!")
if (!Number.isSafeInteger(pointAmount)) return message.reply(`${botConfig.SERVER_POINTS_NAME} amount isn't a number or it is too large!`)
if (pointAmount === 0) return message.reply(`You can't bet zero ${botConfig.SERVER_POINTS_NAME}, silly!`)
if(Math.sign(pointAmount) === -1) return message.reply(`You can't bet negative ${botConfig.SERVER_POINTS_NAME}, silly!`)
if (points[message.author.id].points < pointAmount) return message.reply(`You don't have enough ${botConfig.SERVER_POINTS_NAME} for that, silly!`)
let winningChances = Math.floor(Math.random() * 2) + 1
points[message.author.id] = {
points: points[message.author.id].points - pointAmount
Expand All @@ -33,13 +33,15 @@ module.exports = class test {
}
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.addField("**🌟 Server Points 🌟**",`${message.author} just bet **${pointAmount}** points on heads and **doubled** it to **${parseInt(args[2]) * 2}**!`,false)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${message.author} just bet **${pointAmount}** ${botConfig.SERVER_POINTS_NAME} on heads and **doubled** it to **${parseInt(args[2]) * 2}**!`)
message.channel.send(embed);
} else if (args[1] === "tails") {
// Lose
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.addField("**🌟 Server Points 🌟**",`${message.author} just bet **${pointAmount}** points on tails and **lost** it!`,false)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${message.author} just bet **${pointAmount}** ${botConfig.SERVER_POINTS_NAME} on tails and **lost** it!`)
message.channel.send(embed);
}
} else if (winningChances === 2) {
Expand All @@ -51,13 +53,15 @@ module.exports = class test {
}
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.addField("**🌟 Server Points 🌟**",`${message.author} just bet **${pointAmount}** points on tails and **doubled** it to **${parseInt(args[2]) * 2}**!`,false)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${message.author} just bet **${pointAmount}** ${botConfig.SERVER_POINTS_NAME} on tails and **doubled** it to **${parseInt(args[2]) * 2}**!`)
message.channel.send(embed);
} else if (args[1] === "heads") {
// Lose
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.addField("**🌟 Server Points 🌟**",`${message.author} just bet **${pointAmount}** points on heads and **lost** it!`,false)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${message.author} just bet **${pointAmount}** ${botConfig.SERVER_POINTS_NAME} on heads and **lost** it!`)
message.channel.send(embed);
}
}
Expand Down
1 change: 0 additions & 1 deletion commands/coinflip.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = class test {

async run(bot, message, args) {
const commandData = require("./command-data.json")

message.reply(commandData["COINFLIPS"][Math.floor(Math.random() * commandData["COINFLIPS"].length)])
}
}
1 change: 0 additions & 1 deletion commands/highfive.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = class test {

async run(bot, message, args) {
const commandData = require("./command-data.json")

let highfiveUser = message.guild.member(message.mentions.users.first())
if (!highfiveUser) return message.reply("User not found!")
if (highfiveUser.id != message.author.id) {
Expand Down
1 change: 0 additions & 1 deletion commands/kill.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = class test {

async run(bot, message, args) {
const commandData = require("./command-data.json")

let killUser = message.guild.member(message.mentions.users.first())
if (!killUser) return message.reply("User not found!")
if (killUser.id != message.author.id) {
Expand Down
77 changes: 49 additions & 28 deletions commands/pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,64 @@ const Discord = require("discord.js");
module.exports = class test {
constructor(){
this.name = 'pay',
this.alias = ['send','sendpoints','paypoints']
this.alias = ['send','send-xels','pay-xels']
this.usage = ';pay {user} {amount}'
}

async run(bot, message, args) {
const fs = require("fs")
let points = require("./../points.json")
async run(bot, message, args, connection) {
const botConfig = require("./../bot-config.json")
if (!points[message.author.id]) return message.reply("You don't have any points, silly!")
let payUser = message.guild.member(message.mentions.users.first())
if (!payUser) return message.reply("User not found!")
if (payUser == message.guild.member(message.author)) return message.reply("You can't pay yourself, silly!")
if (!args[2]) return message.reply("Point amount not found!")
if (!args[2]) return message.reply(`${botConfig.SERVER_POINTS_NAME} amount not found!`)
let pointAmount = parseInt(args[2])
if (!Number.isSafeInteger(pointAmount)) return message.reply("Point amount isn't a number or it is too large!")
if (pointAmount === 0) return message.reply("You can't pay zero points, silly!")
if(Math.sign(pointAmount) === -1) return message.reply("You can't pay negative points, silly!")
if (points[message.author.id].points < pointAmount) return message.reply("You don't have enough points for that, silly!")
if (!points[payUser.id]) {
points[payUser.id] = {
points: 0
if (!Number.isSafeInteger(pointAmount)) return message.reply(`${botConfig.SERVER_POINTS_NAME} amount isn't a number or it is too large!`)
if (pointAmount === 0) return message.reply(`You can't pay zero ${botConfig.SERVER_POINTS_NAME}, silly!`)
if(Math.sign(pointAmount) === -1) return message.reply(`You can't pay negative ${botConfig.SERVER_POINTS_NAME}, silly!`)
let completed = false
let cancel = false
connection.query(`SELECT * FROM points WHERE id = '${message.author.id}'`, (err, rows) => {
if (err) throw err
let sql
if (rows.length < 1) {
sql = `INSERT INTO points(id, points) VALUES ('${message.author.id}', 0)`
cancel = true
} else {
if (rows[0].points >= pointAmount) {
sql = ` UPDATE points SET points = ${rows[0].points - pointAmount} WHERE id = '${message.author.id}'`
} else {
cancel = true
}
}
};
let payPoints = points[payUser.id].points
let selfPoints = points[message.author.id].points
points[message.author.id] = {
points: selfPoints - pointAmount
}
points[payUser.id] = {
points: payPoints + pointAmount
}
fs.writeFile("./../points.json", JSON.stringify(points), (err) => {
if (err) console.log(`[SAVE POINTS ERROR] ${err} in ${message.guild.name} (${message.guild.id})`)
if (cancel != true) {
connection.query(sql)
}
completed = true
})
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.addField("**🌟 Server Points 🌟**",`${message.author} just gave ${payUser} **${pointAmount}** points!`,false)
message.channel.send(embed);
cont()
function cont(){
if (completed){
if (cancel) {
return message.reply(`You don't have enough ${botConfig.SERVER_POINTS_NAME} for that, silly!`)
}
connection.query(`SELECT * FROM points WHERE id = '${payUser.id}'`, (err, rows) => {
if (err) throw err
let sql
if (rows.length < 1) {
sql = `INSERT INTO points(id, points) VALUES ('${payUser.id}', ${pointAmount})`
} else {
sql = ` UPDATE points SET points = ${rows[0].points + pointAmount} WHERE id = '${payUser.id}'`
}
connection.query(sql)
})
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${message.author} just gave ${payUser} **${pointAmount}** ${botConfig.SERVER_POINTS_NAME}!`)
message.channel.send(embed);
} else {
setTimeout(cont, 100);
}
}
}
}
1 change: 0 additions & 1 deletion commands/punch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = class test {

async run(bot, message, args) {
const commandData = require("./command-data.json")

let punchUser = message.guild.member(message.mentions.users.first())
if (!punchUser) return message.reply("User not found!")
if (punchUser.id != message.author.id) {
Expand Down
1 change: 0 additions & 1 deletion commands/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = class test {

async run(bot, message, args) {
const commandData = require("./command-data.json")

message.react(commandData["EMOJIS"][Math.floor(Math.random() * commandData["EMOJIS"].length)])
}
}
1 change: 0 additions & 1 deletion commands/rtd.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = class test {

async run(bot, message, args) {
const commandData = require("./command-data.json")

message.reply(commandData["RTDs"][Math.floor(Math.random() * commandData["RTDs"].length)])
}
}
40 changes: 40 additions & 0 deletions commands/scavenge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const Discord = require("discord.js");
let scavengeCooldown = new Set()

module.exports = class test {
constructor(){
this.name = 'scavenge',
this.alias = ['scavenge']
this.usage = ';scavenge'
}

async run(bot, message, args, connection) {
if (scavengeCooldown.has(message.author.id)) {
message.reply("You must wait for the scavenge cooldown to end (5 minutes)!")
return
} else {
const botConfig = require("./../bot-config.json")
let pointsAmt = Math.floor(Math.random() * botConfig.MAX_WORK_AMOUNT) + 1;
connection.query(`SELECT * FROM points WHERE id = '${message.author.id}'`, (err, rows) => {
if (err) throw err
let sql
if (rows.length < 1) {
sql = `INSERT INTO points(id, points) VALUES ('${message.author.id}', ${pointsAmt})`
} else {
let points = rows[0].points
sql = ` UPDATE points SET points = ${points + pointsAmt} WHERE id = '${message.author.id}'`
}
connection.query(sql)
})
var embed = new Discord.RichEmbed()
.setColor(botConfig.SERVER_POINTS_UI_COLOR)
.setTitle(`**${bot.emojis.get("675022811395260433")} ${botConfig.SERVER_POINTS} ${bot.emojis.get("675022811395260433")}**`)
.setDescription(`${message.author} just scavenged for **${pointsAmt}** ${botConfig.SERVER_POINTS_NAME}!`)
message.channel.send(embed);
scavengeCooldown.add(message.author.id)
setTimeout(() => {
scavengeCooldown.delete(message.author.id)
}, botConfig.POINTS_COOLDOWN * 1000)
}
}
}
1 change: 0 additions & 1 deletion commands/slap.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = class test {

async run(bot, message, args) {
const commandData = require("./command-data.json")

let slapUser = message.guild.member(message.mentions.users.first())
if (!slapUser) return message.reply("User not found!")
if (slapUser.id != message.author.id) {
Expand Down
Loading

0 comments on commit a3ab8e9

Please sign in to comment.