Skip to content

Commit

Permalink
Updated!
Browse files Browse the repository at this point in the history
Updated everything.
The commands `kc!vote` and `kc!help` aren't functional right now though.
  • Loading branch information
Zaczer authored May 5, 2021
1 parent 0163edf commit 13b4d8c
Show file tree
Hide file tree
Showing 28 changed files with 636 additions and 104 deletions.
17 changes: 13 additions & 4 deletions Files/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
{
"name": "kc-bot",
"version": "1.0.5",
"description": "kc-mod-bot - Zaczer",
"version": "1.0.6",
"description": "",
"main": "index.js",
"scripts": {
"start": "node ./src/index.js",
"dev": "nodemon ./src/index.js"
},
"author": "Zaczer",
"license": "MIT",
"license": "ISC",
"dependencies": {
"canvas": "^2.7.0",
"crypto": "^1.0.1",
"discord-reply": "^0.1.2",
"discord.js": "^12.5.1",
"dotenv": "^8.2.0",
"fs": "0.0.1-security",
"fs": "^0.0.1-security",
"http": "0.0.1-security",
"https": "^1.0.0",
"moment": "^2.29.1",
"mongo": "^0.1.0",
"mongoose": "^5.12.5",
"path": "^0.12.7",
"unirest": "^0.6.0"
},
"devDependencies": {
Expand Down
40 changes: 27 additions & 13 deletions Files/src/commands/command-base.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const mongo = require('../mongo')
const fs = require('fs')
const commandPrefixSchema = require('../schemas/command-prefix-schema')
const guildPrefixes = {} // { 'guildID' : 'prefix' }
const { prefix: globalPrefix } = require('../config.json')
const { Client, Channel } = require ('discord.js')
const client = new Client();
const Discord = require('discord.js')
const { version } = require ('../config.json')
const { embedIcon } = require ('../config.json')

//Ensures permissions listed in commands are valid.
const validatePermissions = (permissions) => {
const validatePermissions = [
Expand Down Expand Up @@ -66,28 +73,34 @@ module.exports = (client, commandOptions) => {



// Ensure permissions are in and array and valid.
//Ensure permissions are in and array and valid.
if (permissions.length) {
if (typeof permissions === 'string') {
permissions = [permissions]
}
validatePermissions(permissions)
}
// Listen for messages.
//Listen for messages.
client.on('message', message => {
const { member, content, guild } = message
const prefix = guildPrefixes[guild.id] || globalPrefix

try { const prefix = guildPrefixes[guild.id] || globalPrefix} catch { return }

for (const alias of commands) {
if (content.toLowerCase().startsWith(`${prefix}${alias.toLowerCase()}`)) {
// A command has been ran.
const command = `${prefix}${alias.toLowerCase()}`

if (
content.toLowerCase().startsWith(`${command} `) ||
content.toLowerCase() === command
) {
//A command has been ran

// Ensure user has required permissions.
//Ensure user has required permissions.
for (const permission of permissions) {
if (!member.hasPermission(permission)) {
message.reply(permissionError)
message.lineReplyNoMention(permissionError)
.then(message => {
setTimeout(() => message.delete(), 10000)
setTimeout(() => message.delete(), 3000)
})
return
}
Expand All @@ -98,9 +111,9 @@ module.exports = (client, commandOptions) => {
role.name == requiredRole)

if (!role || member.roles.cache.has(role.id)) {
member.reply(`You must have the "${requiredRole} role to use this command.`)
member.lineReplyNoMention(`You must have the "${requiredRole} role to use this command.`)
.then(message => {
setTimeout(() => message.delete(), 10000)
setTimeout(() => message.delete(), 3000)
})
return
}
Expand All @@ -113,14 +126,14 @@ module.exports = (client, commandOptions) => {
if (arguments.length < minArgs || (
maxArgs !== null && arguments.length > maxArgs
)) {
message.reply(`Incorret syntax! Use ${prefix}${alias} ${expectedArgs}.`)
message.lineReplyNoMention(`Incorret syntax! Use ${prefix}${alias} ${expectedArgs}.`)
.then(message => {
setTimeout(() => message.delete(), 10000)
setTimeout(() => message.delete(), 3000)
})
return
}

//Handle custom command code.
//Handle custom command outputs.
callback(message, arguments, arguments.join(' '))


Expand All @@ -130,6 +143,7 @@ module.exports = (client, commandOptions) => {
})
}

//Load mongo and custom prefixes.
module.exports.loadPrefixes = async (client) => {
await mongo().then(async mongoose => {
try {
Expand Down
16 changes: 16 additions & 0 deletions Files/src/commands/fun/clap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

const Discord = require('discord.js');
const { Client, Channel } = require ('discord.js')
const client = new Client();

module.exports = {
commands:['clap', 'cheer'],
expectedArgs: '<text>',
minArgs: 1,
callback: (message, arguments, text) => {
let sentence = arguments.join(' 👏 ');

message.lineReplyNoMention(sentence)
},
permissions: 'SEND_MESSAGES'
}
18 changes: 10 additions & 8 deletions Files/src/commands/fun/gif.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
const TENORKEY = require("../../config.json")
const fs = require('fs')
const { TENORKEY } = require('../../config.json')
const { Client, Channel } = require ('discord.js')
const client = new Client()
const fetch = require('node-fetch')

module.exports = {
commands:['gif'],
expectedArgs: '<searchTopic>',
minArgs: 1,
maxArgs: 1,
minArgs: 0,
callback: async (message, arguments, text) => {
try {
let keywords = message.mentions.channels.first();
let url = `https://api.tenor.com/v1/search?q=${keywords}&key=${process.env.TENORKEY}&contentfilter=high`;
let response = await fetch(url);
keywords = arguments.join(" ")
let tenorURL = `https://api.tenor.com/v1/search?q=${keywords}&key=${TENORKEY}&contentfilter=high`;
let response = await fetch(tenorURL);
let json = await response.json();
message.channel.send(json.results.url);
const index = Math.floor(Math.random() * json.results.length);
gif = json.results[index].url
message.lineReplyNoMention(gif);
} catch (error) {
message.reply(`error!\n${error.message}`)
message.lineReplyNoMention(`Error!\n${error.message}`)
.then(message => {
setTimeout(() => message.delete(), 10000)
})
Expand Down
4 changes: 2 additions & 2 deletions Files/src/commands/fun/owofy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
minArgs: 1,
callback: (message, arguments, text) => {
let sentence = arguments.join(' ');
if (!sentence) return message.reply('I can\'t owo-fy an empty message! uwu');
if (!sentence) return message.lineReplyNoMention('I can\'t owo-fy an empty message! uwu');

let faces=["(・`ω´・)",";;w;;","owo","UwU",">w<","^w^"];

Expand All @@ -22,7 +22,7 @@ module.exports = {
newSentence = newSentence.replace(/ove/g, "uv");
newSentence = newSentence.replace(/\!+/g, " "+ faces[Math.floor(Math.random()*faces.length)]+ " ");
// fuck you this is now finished
message.channel.send(newSentence);
message.lineReplyNoMention(newSentence);
message.delete()
},
permissions: 'SEND_MESSAGES'
Expand Down
30 changes: 30 additions & 0 deletions Files/src/commands/load-commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const path = require('path')
const fs = require('fs')


module.exports = (client) => {
const baseFile = 'command-base.js'
const commandBase = require(`../commands/${baseFile}`)

const commands = []

const readCommands = (dir) => {
const files = fs.readdirSync(path.join(__dirname, dir))
for (const file of files) {
const stat = fs.lstatSync(path.join(__dirname, dir, file))
if (stat.isDirectory()) {
readCommands(path.join(dir, file))
} else if (file !== baseFile && file !== 'load-commands.js') {
const option = require(path.join(__dirname, dir, file))
commands.push(option)
if (client) {
commandBase(client, option)
}
}
}
}

readCommands('.')

return commands
}
8 changes: 4 additions & 4 deletions Files/src/commands/misc/embed-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
//Use targeted channel
const targetChannel = message.mentions.channels.first();
if (!targetChannel) {
message.reply('please specifiy channel.')
message.lineReplyNoMention('Please specifiy channel.')
.then(message => {
setTimeout(() => message.delete(), 10000)
})
Expand All @@ -26,15 +26,15 @@ module.exports = {
embed: json
})

//Reply to confirm
message.reply('message sent!')
//lineReplyNoMention to confirm
message.lineReplyNoMention('Message sent!')
.then(message => {
setTimeout(() => message.delete(), 2000)
})
message.delete()

} catch (error) {
message.reply(`you used invalid JSON data!\n ${error.message}`)
message.lineReplyNoMention(`You used invalid JSON data!\n ${error.message}`)
.then(message => {
setTimeout(() => message.delete(), 10000)
})
Expand Down
6 changes: 3 additions & 3 deletions Files/src/commands/misc/say.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
//Use targeted channel
const targetChannel = message.mentions.channels.first();
if (!targetChannel) {
message.reply('please specifiy channel.')
message.lineReplyNoMention('Please specifiy channel.')
.then(message => {
setTimeout(() => message.delete(), 10000)
})
Expand All @@ -24,14 +24,14 @@ module.exports = {
targetChannel.send(text)

//Reply to confirm
message.reply('message sent!')
message.lineReplyNoMention('Message sent!')
.then(message => {
setTimeout(() => message.delete(), 2000)
})
message.delete()

} catch (error) {
message.reply(`error! ${error.message}`)
message.lineReplyNoMention(`Error! ${error.message}`)
}
},
permissions: 'MANAGE_GUILD'
Expand Down
50 changes: 50 additions & 0 deletions Files/src/commands/misc/vote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { Client, Channel } = require ('discord.js')
const client = new Client();
const Discord = require('discord.js')
const { version } = require ('../../config.json')
const { embedIcon } = require ('../../config.json')

module.exports = {
commands:['vote'],
description: 'Makes an anonymous vote.',
expectedArgs: '<vote>',
minArgs: 1,
callback: async (message, arguments, text) => {
const vote = arguments.join(" ")
var yesCounter = 0
var noCounter = 0
const embed = new Discord.MessageEmbed()
.setTitle(`__Anonymous Vote!__`)
.addField(`${vote}\n\n`, `<:upvote:707157967471902731> - ${yesCounter} votes.\n <:downvote:707158001496096808> - ${noCounter} votes.`)
.setColor('#a3ebfb')
.setFooter(`${version}`, embedIcon)
const sentEmbed = await message.channel.send(embed)
await sentEmbed.react('<:upvote:707157967471902731>')
await sentEmbed.react('<:downvote:707158001496096808>')
const filter = (reaction, user) => (['<:upvote:707157967471902731>', '<:downvote:707158001496096808>'].includes(reaction.emoji.name) && !user.bot)
const collector = sentEmbed.createReactionCollector(filter)

downvotedEmbed = new Discord.MessageEmbed()
.setTitle(`__Anonymous Vote!__`)
.addField(`${vote}\n\n`, `<:upvote:707157967471902731> - ${yesCounter} votes.\n <:downvote:707158001496096808> - ${noCounter +1} votes.`)
.setColor('#a3ebfb')
.setFooter(`${version}`, embedIcon)
upvotedEmbed = new Discord.MessageEmbed()
.setTitle(`__Anonymous Vote!__`)
.addField(`${vote}\n\n`, `<:upvote:707157967471902731> - ${yesCounter +1} votes.\n <:downvote:707158001496096808> - ${noCounter} votes.`)
.setColor('#a3ebfb')
.setFooter(`${version}`, embedIcon)

collector.on("collect", (reaction, user) => {
switch (reaction.emoji.name) {
case '<:upvote:707157967471902731>':
sentEmbed.edit(upvotedEmbed);
break;
case '<:downvote:707158001496096808>':
sentEmbed.edit(downvotedEmbed);
break;
}
});
},
permissions: 'MANAGE_GUILD'
}
17 changes: 17 additions & 0 deletions Files/src/commands/moderation/ban.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const Discord = require('discord.js')

module.exports = {
commands: ['ban'],
description: 'Bans a member.',
expectedArgs: '<mentionMember> <banReason>',
minArgs: 1,
permissions: 'BAN_MEMBERS',
callback: (message, arguments, text) => {
var memberToBan = message.guild.member(message.mentions.users.first())
arguments.shift()
var banReason = arguments
memberToBan.ban({reason: `${banReason}`})
message.lineReplyNoMention(`${memberToBan} has been banned for the reason: \`${banReason}\`.`)
}

}
8 changes: 4 additions & 4 deletions Files/src/commands/moderation/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ module.exports = {

const amount = arguments.join(" ");

if(!amount) return message.reply('please provide an amount of messages for me to delete!')
if(!amount) return message.lineReplyNoMention('Please provide an amount of messages for me to delete!')

if(amount > 100) return message.reply(`you cannot clear more than 100 messages at once.`)
if(amount > 1000) return message.lineReplyNoMention(`You cannot clear more than 100 messages at once.`)

await message.channel.messages.fetch({limit: amount}).then(messages => {
message.channel.bulkDelete(messages
)});


message.channel.send(`Deleted ${amount} messages!`)
message.lineReplyNoMention(`Deleted ${amount} messages!`)
.then(message => {
setTimeout(() => message.delete(), 2000)
setTimeout(() => message.delete(), 5000)
})

},
Expand Down
6 changes: 3 additions & 3 deletions Files/src/commands/moderation/list-warnings.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = {
callback: async (message, arguments, text) => {
const target = message.mentions.users.first()
if (!target) {
message.reply('Please specify a user to load the warnings for.')
message.lineReplyNoMention('Please specify a user to load the warnings for.')
return
}

Expand All @@ -33,10 +33,10 @@ module.exports = {
).toLocaleDateString()} for "${reason}"\n\n`
}
} catch {
message.reply('no previous warnings found.')
message.lineReplyNoMention('No previous warnings found.')
return
}
message.reply(reply)
message.lineReplyNoMention(reply)
} finally {
mongoose.connection.close()
}
Expand Down
Loading

0 comments on commit 13b4d8c

Please sign in to comment.