From ed24fac246764b20ad0130c65d8b407456ccd62b Mon Sep 17 00:00:00 2001 From: Benjamin Kyd Date: Tue, 14 Jul 2020 00:28:33 +0100 Subject: [PATCH] added events --- src/discord.js | 17 +++++++++------ src/discordcommands.js | 13 +++++++++++ src/discordevents.js | 49 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/src/discord.js b/src/discord.js index 77e5fc0..25d7d58 100644 --- a/src/discord.js +++ b/src/discord.js @@ -1,11 +1,12 @@ const Logger = require('./logger.js'); -const Database = require('./database.js'); +const Events = require('./discordevents.js'); +const Commands = require('./discordcommands.js'); const fs = require('fs'); const Eris = require('eris'); -let bot; +module.exports.bot; module.exports.setup = async function() { @@ -13,10 +14,10 @@ module.exports.setup = async function() if (!process.env.BOT_TOKEN) Logger.panic('No BOT_TOKEN in .env file!') - bot = new Eris(process.env.BOT_TOKEN, {allowedMentions: false, restMode: true}); + this.bot = new Eris(process.env.BOT_TOKEN, {allowedMentions: false, restMode: true}); - bot.on('ready', async () => { - Logger.info(`Discord logged in as ${bot.user.username}#${bot.user.discriminator}`); + this.bot.on('ready', async () => { + Logger.info(`Discord logged in as ${this.bot.user.username}#${this.bot.user.discriminator}`); let typestr = process.env.BOT_GAME_TYPE || 'playing'; let game = process.env.BOT_GAME || '*'; @@ -29,12 +30,14 @@ module.exports.setup = async function() default: type = 3; break; } - bot.editStatus('online', {name: game, type: type}); + this.bot.editStatus('online', {name: game, type: type}); }); // settup events + Events.setup(); + Commands.registerCommands(); - bot.connect(); + this.bot.connect(); } diff --git a/src/discordcommands.js b/src/discordcommands.js index e69de29..7ee75d8 100644 --- a/src/discordcommands.js +++ b/src/discordcommands.js @@ -0,0 +1,13 @@ +const Logger = require('./logger.js'); + +let Commands = {}; + +module.exports.registerCommands = async function() +{ + Logger.info('Registering commands'); +} + +module.exports.newMessage = async function(message) +{ + console.log(message.content); +} diff --git a/src/discordevents.js b/src/discordevents.js index e69de29..b901b55 100644 --- a/src/discordevents.js +++ b/src/discordevents.js @@ -0,0 +1,49 @@ +const Logger = require('./logger.js'); +const Discord = require('./discord.js'); +const Commands = require('./discordcommands.js'); + +module.exports.setup = async function() +{ + Logger.info('Setting up discord listeners'); + + Discord.bot.on('channelCreate', async (channel) => {}); + Discord.bot.on('channelDelete', async (channel) => {}); + Discord.bot.on('channelPinUpdate', async (channel, timestamp, oldtimestamp) => {}); + Discord.bot.on('channelUpdate', async (channel, oldchannel) => {}); + Discord.bot.on('guildBanAdd', async (guild, user) => {}); + Discord.bot.on('guildBanRemove', async (guild, user) => {}); + Discord.bot.on('guildCreate', async (guild) => {}); + Discord.bot.on('guildDelete', async (guild) => {}); + Discord.bot.on('guildEmojisUpdate', async (guild, emojis, oldemojis) => {}); + Discord.bot.on('guildMemberAdd', async (guild, member) => {}); + Discord.bot.on('guildMemberRemove', async (guild, member) => {}); + Discord.bot.on('guildMemberUpdate', async (guild, member, oldmember) => {}); + Discord.bot.on('guildRoleCreate', async (guild, role) => {}); + Discord.bot.on('guildRoleDelete', async (guild, role) => {}); + Discord.bot.on('guildRoleUpdate', async (guild, role, oldrole) => {}); + Discord.bot.on('guildUpdate', async (guild, oldguild) => {}); + Discord.bot.on('inviteCreate', async (guild, invite) => {}); + Discord.bot.on('inviteDelete', async (guild, invite) => {}); + Discord.bot.on('messageCreate', async (message) => Commands.newMessage(message)); + Discord.bot.on('messageDelete', async (message) => {}); + Discord.bot.on('messageDeleteBulk', async (messages) => {}); + Discord.bot.on('messageReactionAdd', async (message, emoji) => {}); + Discord.bot.on('messageReactionRemove', async (message, emoji) => {}); + Discord.bot.on('messageReactionRemoveAll', async (message) => {}); + Discord.bot.on('messageReactionRemoveEmoji', async (message, emoji) => {}); + Discord.bot.on('messageUpdate', async (message, oldmessage) => {}); + Discord.bot.on('presenceUpdate', async (member, oldprescence) => {}); + Discord.bot.on('userUpdate', async (user, olduser) => {}); + Discord.bot.on('voiceChannelJoin', async (member, newchannel) => {}); + Discord.bot.on('voiceChannelLeave', async (member, oldchannel) => {}); + Discord.bot.on('voiceChannelSwitch', async (member, newchannel, oldchannel) => {}); + Discord.bot.on('voiceStateUpdate', async (member, oldstate) => {}); + Discord.bot.on('webhooksUpdate', async (data, channelid, guildid) => {}); + Discord.bot.on('warn', async (message, id) => {}); + Discord.bot.on('error', async (error, id) => {}); + Discord.bot.on('disconnect', async (options) => {}); +} + +// Handlers + +