forked from embee/woomy
did stuff
This commit is contained in:
parent
57fb111d3b
commit
10a0a7aca7
9 changed files with 1229 additions and 51 deletions
|
@ -0,0 +1,22 @@
|
|||
exports.conf = {
|
||||
enabled: true,
|
||||
guildOnly: false,
|
||||
aliases: [],
|
||||
permLevel: 'User',
|
||||
requiredPerms: [],
|
||||
cooldown: 2000
|
||||
}
|
||||
|
||||
exports.help = {
|
||||
name: 'ping',
|
||||
category: 'Utility',
|
||||
description: 'Displays bot latency in miliseconds.',
|
||||
usage: 'ping'
|
||||
}
|
||||
|
||||
exports.run = async (client, message) => {
|
||||
const msg = await message.channel.send('⏱️ Please wait...')
|
||||
msg.edit(
|
||||
`:ping_pong: Pong! Latency is ${msg.createdTimestamp - message.createdTimestamp}ms, API Latency is ${Math.round(client.ws.ping)}ms`
|
||||
)
|
||||
}
|
|
@ -4,8 +4,7 @@ const config = {
|
|||
|
||||
// Default settings for individual users
|
||||
defaultUserSettings: {
|
||||
prefixes: ['~'],
|
||||
systemNotice: true
|
||||
prefixes: ['~']
|
||||
},
|
||||
|
||||
// Default per-guild settings
|
||||
|
|
49
events/message.js
Normal file
49
events/message.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
|
||||
const Discord = require('discord.js')
|
||||
const cooldown = new Discord.Collection()
|
||||
module.exports = async (client, message) => {
|
||||
if (message.author.bot) return
|
||||
|
||||
var prefix = '~'
|
||||
|
||||
const myMention = `<@&${client.user.id}>`
|
||||
const myMention2 = `<@!${client.user.id}>`
|
||||
|
||||
if (message.content.startsWith(myMention) || message.content.startsWith(myMention2)) {
|
||||
if (message.content.length > myMention.length + 1 && (message.content.substr(0, myMention.length + 1) === myMention + ' ' || message.content.substr(0, myMention2.length + 1) === myMention2 + ' ')) {
|
||||
prefix = message.content.substr(0, myMention.length) + ' '
|
||||
} else {
|
||||
return message.channel.send(`Current prefix: \`${prefix}\``)
|
||||
};
|
||||
};
|
||||
|
||||
if (message.content.indexOf(prefix) !== 0) return
|
||||
|
||||
const args = message.content.slice(prefix.length).trim().split(/ +/g)
|
||||
const command = args.shift().toLowerCase()
|
||||
|
||||
if (message.guild && !message.member) await message.guild.fetchMember(message.author)
|
||||
|
||||
const level = client.permlevel(message)
|
||||
|
||||
const cmd = client.commands.get(command) || client.commands.get(client.aliases.get(command))
|
||||
if (!cmd) return
|
||||
|
||||
if (cmd && !message.guild && cmd.conf.guildOnly) {
|
||||
return message.channel.send('This command is unavailable via private message. Please run this command in a guild.')
|
||||
}
|
||||
|
||||
if (level < client.levelCache[cmd.conf.permLevel]) {
|
||||
return message.channel.send('You don\'t have permission to run this command!')
|
||||
}
|
||||
|
||||
message.author.permLevel = level
|
||||
|
||||
message.flags = []
|
||||
while (args[0] && args[0][0] === '-') {
|
||||
message.flags.push(args.shift().slice(1))
|
||||
}
|
||||
|
||||
client.logger.log(`Command ran: ${cmd.help.name}`)
|
||||
cmd.run(client, message, args, level)
|
||||
}
|
|
@ -1,3 +1,3 @@
|
|||
module.exports = (client) => {
|
||||
client.logger.log.ready('Discord client ready!')
|
||||
client.logger.ready('Connected to Discord as ' + client.user.tag)
|
||||
}
|
||||
|
|
41
index.js
41
index.js
|
@ -9,19 +9,36 @@ if (Number(process.version.slice(1).split('.')[0]) < 12) {
|
|||
|
||||
// Load environment variables / config
|
||||
const fs = require('fs')
|
||||
const colors = require('colors')
|
||||
const Discord = require('discord.js')
|
||||
const client = new Discord.Client({ disabledEvents: ['TYPING_START'] })
|
||||
|
||||
require('./modules/functions')(client)
|
||||
client.logger = require('./modules/logger')
|
||||
|
||||
client.logger = require('tracer').colorConsole({
|
||||
format: [
|
||||
'{{timestamp}} <{{title}}> ({{file}}) {{message}}'
|
||||
],
|
||||
dateformat: 'dd-mm-yyyy HH:MM:ss',
|
||||
methods: ['log', 'debug', 'info', 'ready', 'warn', 'error', 'fatal'],
|
||||
filters: [{
|
||||
log: colors.white,
|
||||
debug: colors.magenta,
|
||||
info: colors.cyan,
|
||||
ready: colors.green,
|
||||
warn: colors.yellow,
|
||||
error: colors.red,
|
||||
fatal: [colors.red, colors.bold]
|
||||
}]
|
||||
})
|
||||
|
||||
if (fs.existsSync('./.env') === false) {
|
||||
client.logger.log.error('The .env file is missing! Please create a .env file.')
|
||||
client.logger.fatal('The .env file is missing! Please create a .env file.')
|
||||
process.exit()
|
||||
}
|
||||
|
||||
if (fs.existsSync('./config.js') === false) {
|
||||
client.logger.log.error('The config.js file is missing! Please create a config.js file.')
|
||||
client.logger.fatal('The config.js file is missing! Please create a config.js file.')
|
||||
process.exit()
|
||||
}
|
||||
|
||||
|
@ -39,14 +56,30 @@ const init = async () => {
|
|||
// Load events
|
||||
fs.readdir('./events', (err, files) => {
|
||||
if (err) {}
|
||||
client.logger.log.info(`Loading ${files.length} events.`)
|
||||
client.logger.info(`Loading ${files.length} events.`)
|
||||
files.forEach(file => {
|
||||
if (!file.endsWith('.js')) {
|
||||
return
|
||||
}
|
||||
const event = require(`./events/${file}`)
|
||||
client.on(file.substr(0, file.length - 3), event.bind(null, client))
|
||||
})
|
||||
})
|
||||
|
||||
// Load commands
|
||||
fs.readdir('./commands', (err, files) => {
|
||||
if (err) {}
|
||||
client.logger.info(`Loading ${files.length} commands.`)
|
||||
files.forEach(file => {
|
||||
if (!file.endsWith('.js')) {
|
||||
return
|
||||
}
|
||||
const response = client.loadCommand(file)
|
||||
if (response) {
|
||||
client.logger.error(response)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// Level cache
|
||||
client.levelCache = {}
|
||||
|
|
|
@ -1,3 +1,27 @@
|
|||
module.exports = client => {
|
||||
client.loadCommand = (commandName) => {
|
||||
try {
|
||||
const props = require(`../commands/${commandName}`)
|
||||
if (props.init) {
|
||||
props.init(client)
|
||||
}
|
||||
client.commands.set(props.help.name, props)
|
||||
props.conf.aliases.forEach(alias => {
|
||||
client.aliases.set(alias, props.help.name)
|
||||
})
|
||||
return false
|
||||
} catch (e) {
|
||||
return `Failed to load ${commandName}: ${e}`
|
||||
}
|
||||
}
|
||||
|
||||
process.on('uncaughtException', (err) => {
|
||||
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, 'g'), './')
|
||||
client.logger.fatal(`Uncaught Exception: ${errorMsg}`)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', err => {
|
||||
client.logger.error(`Unhandled rejection: ${err}`)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
const winston = require('winston')
|
||||
const path = require('path')
|
||||
const root = path.join(__dirname, '..')
|
||||
|
||||
const levels = {
|
||||
levels: {
|
||||
error: 0,
|
||||
warn: 1,
|
||||
ready: 2,
|
||||
info: 3,
|
||||
cmd: 4
|
||||
},
|
||||
colors: {
|
||||
error: 'red',
|
||||
warn: 'yellow',
|
||||
ready: 'green',
|
||||
info: 'cyan',
|
||||
cmd: 'white'
|
||||
}
|
||||
}
|
||||
|
||||
winston.addColors(levels.colors)
|
||||
|
||||
const format = winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.timestamp({
|
||||
format: 'DD-MM-YYYY HH:mm:ss'
|
||||
}),
|
||||
winston.format.printf(
|
||||
info => `${info.timestamp} - ${info.level}: ${info.message}`
|
||||
)
|
||||
)
|
||||
|
||||
const logger = winston.createLogger({
|
||||
levels: levels.levels,
|
||||
format: format,
|
||||
transports: [
|
||||
new winston.transports.Console()
|
||||
]
|
||||
})
|
||||
|
||||
logger.exitOnError = false
|
||||
|
||||
module.exports.log = logger
|
1095
package-lock.json
generated
1095
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue