From f3a9f2dd22dffdc8e55b5228c0a6fea39fd8ae52 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Thu, 1 Mar 2018 12:06:02 -0500 Subject: [PATCH 1/7] Make stuff async --- caps/sasl.js | 22 +++++------ core.js | 56 ++++++++++++++-------------- index.js | 2 +- irc-caps.js | 10 ++--- plugins/general.js | 10 ++--- wrappers.js | 92 +++++++++++++++++++++++----------------------- 6 files changed, 96 insertions(+), 96 deletions(-) diff --git a/caps/sasl.js b/caps/sasl.js index fc304ac..b9f0752 100644 --- a/caps/sasl.js +++ b/caps/sasl.js @@ -20,7 +20,7 @@ class Sasl { * @param {object} bot * @param {array} [args] */ - run(bot, args) { + async run(bot, args) { const mechanisms = args || ['EXTERNAL', 'PLAIN']; if (!this.method) { @@ -36,7 +36,7 @@ class Sasl { if (mechanisms.includes(this.method.toUpperCase())) { if (['plain', 'external'].includes(this.method)) { - bot.send(`AUTHENTICATE ${this.method.toUpperCase()}`); + await bot.send(`AUTHENTICATE ${this.method.toUpperCase()}`); } else { throw new Error('Not implemented yet'); } @@ -49,7 +49,7 @@ class Sasl { * @func * @param {object} event */ - on_authenticate(event) { + async on_authenticate(event) { let password; if (event.arguments[0] === '+') { @@ -59,7 +59,7 @@ class Sasl { password = '+'; } - this.bot.send(`AUTHENTICATE ${password}`); + await this.bot.send(`AUTHENTICATE ${password}`); } } @@ -67,7 +67,7 @@ class Sasl { * @func * @param {object} event */ - on_saslfailed(event) { + async on_saslfailed(event) { this.retries += 1; if (this.method === 'external') { @@ -75,15 +75,15 @@ class Sasl { this.retries = 1; this.method = 'plain'; - this.bot.send('AUTHENTICATE PLAIN'); + await this.bot.send('AUTHENTICATE PLAIN'); } else { - this.bot.send('AUTHENTICATE EXTERNAL'); + await this.bot.send('AUTHENTICATE EXTERNAL'); } } else if (this.method === 'plain') { if (this.retries !== 2) { - this.bot.send('AUTHENTICATE PLAIN'); + await this.bot.send('AUTHENTICATE PLAIN'); } else { - this.bot.send('AUTHENTICATE *'); + await this.bot.send('AUTHENTICATE *'); throw new Error('SASL authentication failed!'); } } @@ -93,8 +93,8 @@ class Sasl { * @func * @param {object} event */ - on_saslsuccess(event) { - this.bot.send('CAP END'); + async on_saslsuccess(event) { + await this.bot.send('CAP END'); } } diff --git a/core.js b/core.js index f56bb26..1b39cc3 100644 --- a/core.js +++ b/core.js @@ -40,7 +40,7 @@ class Core { this.floodProtection = new FloodProtection(this); this.plugins = new Plugins(this); - this.on_error = (irc, event) => { + this.on_error = async (irc, event) => { if (event.arguments.join(' ').indexOf('Closing link') === -1) irc.privmsg('##Athena', 'An error occured, check the console. !att-Athena-admins'); log.error(event.arguments.join(' ')); @@ -51,18 +51,18 @@ class Core { this.send('PONG'); }; - this.on_nicknameinuse = (irc, event) => { + this.on_nicknameinuse = async (irc, event) => { this.nickname = this.nickname.concat('_'); irc.nick(this.nickname); }; - this.on_welcome = (irc, event) => { + this.on_welcome = async (irc, event) => { Object.keys(this.config.channels).forEach(channel => { irc.join(channel, this.config.channels[channel].key); }); }; - this.on_join = (irc, event) => { + this.on_join = async (irc, event) => { let channel = event.target; let args = event.arguments; @@ -97,7 +97,7 @@ class Core { } }; - this.on_name = (irc, event) => { + this.on_name = async (irc, event) => { const channel = event.arguments[1]; const users = event.arguments[2].split(' '); @@ -118,7 +118,7 @@ class Core { } }; - this.on_whospcrpl = (irc, event) => { + this.on_whospcrpl = async (irc, event) => { let nick = event.arguments[3]; if (nick !== 'ChanServ') { @@ -132,11 +132,11 @@ class Core { } }; - this.on_channelmodeis = (irc, event) => { + this.on_channelmodeis = async (irc, event) => { this.state.channels[event.arguments[0]].modes.push(...event.arguments[1].slice(1).split('')); }; - this._update_user_modes = (irc, event, mode) => { + this._update_user_modes = async (irc, event, mode) => { let [channel, user] = event.arguments.slice(0, 2); // let [channel, user, setby, timestamp] = event.arguments; @@ -154,17 +154,17 @@ class Core { } }; - this.on_exceptlist = (irc, event) => this._update_user_modes(irc, event, 'e'); + this.on_exceptlist = async (irc, event) => this._update_user_modes(irc, event, 'e'); - this.on_banlist = (irc, event) => this._update_user_modes(irc, event, 'b'); + this.on_banlist = async (irc, event) => this._update_user_modes(irc, event, 'b'); - this.on_quietlist = (irc, event) => this._update_user_modes(irc, event, 'q'); + this.on_quietlist = async (irc, event) => this._update_user_modes(irc, event, 'q'); - this.on_account = (irc, event) => { + this.on_account = async (irc, event) => { this.channels.change_attr(event.source.nick, 'account', event.target === '*' ? null : event.target); }; - this.on_chghost = (irc, event) => { + this.on_chghost = async (irc, event) => { let args = event.arguments; if (args.length) { @@ -174,11 +174,11 @@ class Core { this.channels.change_attr(event.source.nick, 'host', event.target); }; - this.on_cap = (irc, event) => this.caps.handler(event); + this.on_cap = async (irc, event) => this.caps.handler(event); - this.on_authenticate = (irc, event) => this.sasl.on_authenticate(event); + this.on_authenticate = async (irc, event) => this.sasl.on_authenticate(event); - this.on_saslfailed = (irc, event) => this.sasl.on_saslfailed(event); + this.on_saslfailed = async (irc, event) => this.sasl.on_saslfailed(event); this.on_saslsuccess = (irc, event) => this.sasl.on_saslsuccess(event); @@ -192,28 +192,28 @@ class Core { } }; - this.on_privmsg = (irc, event) => { + this.on_privmsg = async (irc, event) => { let args = event.arguments.join(' ').split(' '); // Split arguments by spaces let prefix = this.config.prefix || ''; if (args[0].startsWith(prefix)) { args[0] = args[0].slice(prefix.length); - this.plugins.call_command(event, irc, args); + await this.plugins.call_command(event, irc, args); } else if (event.target[0] !== '#') { - this.plugins.call_command(event, irc, args); + await this.plugins.call_command(event, irc, args); } else if ( [this.nickname, this.nickname.concat(':'), this.nickname.concat(',')].includes(args[0])) { args.shift(); // nickname[:/,] isn't the commmand - this.plugins.call_command(event, irc, args); + await this.plugins.call_command(event, irc, args); } if (event.target.startsWith('#')) this._update_seen_db(event, irc, event.source.nick, args.join(' ')); - this.plugins.hooks.call_regex(irc, event); - this.plugins.hooks.call_privmsg(irc, event); - this.plugins.hooks.call_includes(irc, event); + await this.plugins.hooks.call_regex(irc, event); + await this.plugins.hooks.call_privmsg(irc, event); + await this.plugins.hooks.call_includes(irc, event); }; - this._get_time = tags => { + this._get_time = async tags => { let timestamp; if (tags.length) { @@ -231,7 +231,7 @@ class Core { return timestamp; }; - this._update_seen_db = (event, irc, nick, str_args) => { + this._update_seen_db = async (event, irc, nick, str_args) => { let timestamp = this._get_time(event.tags); let udb = this.channels[event.target].users[nick]; @@ -247,7 +247,7 @@ class Core { } }; - this.on_ctcp = (irc, event) => { + this.on_ctcp = async (irc, event) => { if (hasattr(this, 'ctcp')) { let ctcp_message = ' '.join(event.arguments).toUpperCase(); @@ -265,7 +265,7 @@ class Core { } }; - this.on_featurelist = (irc, event) => { + this.on_featurelist = async (irc, event) => { for (let param of event.arguments.slice(0, -1)) { let [name, , value] = partition(param, '='); @@ -349,7 +349,7 @@ class Core { * @func * @param {string} message - The message you want to send */ - immediateSend(message) { + async immediateSend(message) { this.socket.write(`${message}\r\n`); log.debug('[SENT] %s', strip_formatting(message)); } diff --git a/index.js b/index.js index d616514..e0076d8 100644 --- a/index.js +++ b/index.js @@ -71,7 +71,7 @@ class Bot extends Core { * Socket connection related stuff. * @function */ - connect() { + async connect() { this.socket.once('connect', () => { log.info('Connected'); diff --git a/irc-caps.js b/irc-caps.js index 62956c8..fe5fdc5 100644 --- a/irc-caps.js +++ b/irc-caps.js @@ -25,7 +25,7 @@ class Caps { * @func * @param {Parser} event */ - handler(event) { + async handler(event) { // Main handling code for CAP const servcaps = event.arguments[1] !== '*' ? event.arguments[1].split(' ') : event.arguments[2].split(' '); @@ -47,16 +47,16 @@ class Caps { if (event.arguments[1] !== '*') { if (!this.availablecaps.length) { - this.bot.send('CAP END'); + await this.bot.send('CAP END'); } else { - this.bot.send(`CAP REQ :${this.availablecaps.join(' ')}`); + await this.bot.send(`CAP REQ :${this.availablecaps.join(' ')}`); } } } else if (event.arguments[0] === 'ACK') { for (const cap of this.caps) { // Iterate over this.caps so we have access to classes if (typeof cap !== 'string' && this.availablecaps.indexOf(cap.name) > -1) { // Check that the cap is in this.availablecaps if (typeof cap.run === 'function') { // Check if the cap has the `run` property - cap.run(this.bot, this.args[cap.name]); // Run the cap with the arguments collected during CAP LS + await cap.run(this.bot, this.args[cap.name]); // Run the cap with the arguments collected during CAP LS } else { continue; } @@ -73,7 +73,7 @@ class Caps { } if (newcaps.length) { - this.bot.send(`CAP REQ :${newcaps.join(' ')}`); // Request the new CAP + await this.bot.send(`CAP REQ :${newcaps.join(' ')}`); // Request the new CAP } } else if (event.arguments[0] === 'DEL') { for (const c of servcaps) { diff --git a/plugins/general.js b/plugins/general.js index dcbfe9f..10c035e 100644 --- a/plugins/general.js +++ b/plugins/general.js @@ -3,14 +3,14 @@ const log = require('../utils/logging'); const util = require('util'); /* eslint-disable require-jsdoc */ -function raw(bot,event,irc,args) { +async function raw(bot,event,irc,args) { irc.send(args.join(" ")) }; raw.opts = { perms: [false, true, true] }; -function flush(bot, event, irc, args) { +async function flush(bot, event, irc, args) { if (args.length) { bot.floodProtection.flushTarget(args[0]) } else { @@ -23,8 +23,8 @@ flush.opts = { aliases: ['flushq'] }; -function todo(bot, event, irc, args) { - let has_perms = check_perms(bot.config, event.source.host, event.target, [true, false, false]); +async function todo(bot, event, irc, args) { + let has_perms = await check_perms(bot.config, event.source.host, event.target, [true, false, false]); if (bot.todo === undefined) bot.todo = require('../todo.json'); if (args[0] === 'add' && has_perms) { @@ -66,7 +66,7 @@ todo.opts = { category: 'general' }; -function ping(bot, event, irc, args) { +async function ping(bot, event, irc, args) { irc.reply(event, 'Pong'); } diff --git a/wrappers.js b/wrappers.js index 3d106ca..ae6a219 100644 --- a/wrappers.js +++ b/wrappers.js @@ -26,11 +26,11 @@ class ConnectionWrapper { * @param {object} event - The event object created when parsing the incoming messages. * @param {string} message - The message you wish to reply with. */ - reply(event, message) { + async reply(event, message) { if (event.target === this.bot.nickname) { - this.privmsg(event.source.nick, message); + await this.privmsg(event.source.nick, message); } else { - this.privmsg(event.target, message); + await this.privmsg(event.target, message); } } @@ -39,7 +39,7 @@ class ConnectionWrapper { * @param {string} target - The user or channel you wish to send a PRIVMSG to. * @param {string} message - The message you wish to send. */ - privmsg(target, message) { + async privmsg(target, message) { const channel = target.startsWith('#') ? target : this.bot.state.channels.keys()[0]; const db = this.bot.state.channels[channel].users[this.bot.nickname]; // The maximum length for messages is 512 bytes total including nick, ident & host @@ -48,15 +48,15 @@ class ConnectionWrapper { let msg = Buffer.from(message); for (let i of range(0, msg.byteLength, MSGLEN)) { - this.bot.send(`PRIVMSG ${target} :${msg.slice(i, i + MSGLEN).toString()}`); + await this.bot.send(`PRIVMSG ${target} :${msg.slice(i, i + MSGLEN).toString()}`); } } /** * @func */ - ping() { - this.bot.send(`PING :${Date.now()}`); + async ping() { + await this.bot.send(`PING :${Date.now()}`); } /** @@ -64,8 +64,8 @@ class ConnectionWrapper { * @func * @param {string} chan - The channel you wish to leave. */ - part(chan) { - this.bot.send(`PART ${chan}`); + async part(chan) { + await this.bot.send(`PART ${chan}`); } /** @@ -73,8 +73,8 @@ class ConnectionWrapper { * @func * @param {string} nick - The nick you wish to change to. */ - nick(nick) { - this.bot.send(`NICK ${nick}`); + async nick(nick) { + await this.bot.send(`NICK ${nick}`); } /** @@ -83,8 +83,8 @@ class ConnectionWrapper { * @param {string} chan - Channel you wish to join. * @param {string} [key] - Channel key. */ - join(chan, key) { - this.bot.send(`JOIN ${chan} ${key || ''}`); + async join(chan, key) { + await this.bot.send(`JOIN ${chan} ${key || ''}`); } /** @@ -93,8 +93,8 @@ class ConnectionWrapper { * @param {string} chan - Channel where you wish to invite user to. * @param {string} user - User whom you would like to invite to specified channel. */ - invite(chan, user) { - this.bot.send(`INVITE ${user} ${chan}`); + async invite(chan, user) { + await this.bot.send(`INVITE ${user} ${chan}`); } /** @@ -103,8 +103,8 @@ class ConnectionWrapper { * @param {string} channel - The channel you wish to send the ACTION to. * @param {string} message - The message you wish to send. */ - action(channel, message) { - this.bot.send(`PRIVMSG ${channel} :\x01ACTION ${message}\x01`); + async action(channel, message) { + await this.bot.send(`PRIVMSG ${channel} :\x01ACTION ${message}\x01`); } /** @@ -114,9 +114,9 @@ class ConnectionWrapper { * @param {string} user - User whom you would like to kick from specified channel. * @param {string} message - Message with which you'd like to kick the specified user with */ - kick(channel, user, message) { + async kick(channel, user, message) { user = user.replace(' ', '').replace(':', ''); - this.bot.send(`KICK ${channel} ${user} :${message}`); + await this.bot.send(`KICK ${channel} ${user} :${message}`); } /** @@ -126,8 +126,8 @@ class ConnectionWrapper { * @param {string} user - User whom you would like to remove from specified channel. * @param {string} message - Message with which you'd like to remove the specified user with */ - remove(channel, user, message) { - this.bot.send(`REMOVE ${channel} ${user} :${message}`); + async remove(channel, user, message) { + await this.bot.send(`REMOVE ${channel} ${user} :${message}`); } /** @@ -136,8 +136,8 @@ class ConnectionWrapper { * @param {string} channel - Channel where you wish to give user from. * @param {string|array} nick - User whom you would like to give operator status to in specified channel. */ - op(channel, nick) { - this.mode(channel, nick, '+o'); + async op(channel, nick) { + await this.mode(channel, nick, '+o'); } /** @@ -146,8 +146,8 @@ class ConnectionWrapper { * @param {string} channel - Channel where you wish to give user from. * @param {string|array} nick - User whom you would like to remove operator status from specified channel. */ - deop(channel, nick) { - this.mode(channel, nick, '-o'); + async deop(channel, nick) { + await this.mode(channel, nick, '-o'); } /** @@ -156,8 +156,8 @@ class ConnectionWrapper { * @param {string} channel - Channel where you wish to ban the user from. * @param {string|array} nick - User whom you would like to ban from specified channel. */ - ban(channel, nick) { - this.mode(channel, nick, '+b'); + async ban(channel, nick) { + await this.mode(channel, nick, '+b'); } /** @@ -166,40 +166,40 @@ class ConnectionWrapper { * @param {string} channel - Channel where you wish to unban the user from. * @param {string|array} nick - User whom you would like to unban from specified channel. */ - unban(channel, nick) { - this.mode(channel, nick, '-b'); + async unban(channel, nick) { + await this.mode(channel, nick, '-b'); } /** * @param {string} channel * @param {string|array} nick */ - quiet(channel, nick) { - this.mode(channel, nick, '+q'); + async quiet(channel, nick) { + await this.mode(channel, nick, '+q'); } /** * @param {string} channel * @param {string|array} nick */ - unquiet(channel, nick) { - this.mode(channel, nick, '-q'); + async unquiet(channel, nick) { + await this.mode(channel, nick, '-q'); } /** * @param {string} channel * @param {string|array} nick */ - unvoice(channel, nick) { - this.mode(channel, nick, '-v'); + async unvoice(channel, nick) { + await this.mode(channel, nick, '-v'); } /** * @param {string} channel * @param {string|arry} nick */ - voice(channel, nick) { - this.mode(channel, nick, '+v'); + async voice(channel, nick) { + await this.mode(channel, nick, '+v'); } /** @@ -207,13 +207,13 @@ class ConnectionWrapper { * @param {string|array} nick * @param {string} mode */ - mode(channel, nick, mode) { + async mode(channel, nick, mode) { if (nick instanceof Array) { for (let i of chunks(nick, this.bot.ISUPPORT.MODES)) { - this.bot.send(`MODE ${channel} ${mode[0].concat(mode.slice(1).repeat(i.length))} ${i.join(' ')}`); + await this.bot.send(`MODE ${channel} ${mode[0].concat(mode.slice(1).repeat(i.length))} ${i.join(' ')}`); } } else { - this.bot.send(`MODE ${channel} ${mode} ${nick}`); + await this.bot.send(`MODE ${channel} ${mode} ${nick}`); } } @@ -221,23 +221,23 @@ class ConnectionWrapper { * @param {string} user * @param {string} message */ - notice(user, message) { - this.bot.send(`NOTICE ${user} :${message}`); + async notice(user, message) { + await this.bot.send(`NOTICE ${user} :${message}`); } /** * @param {string} message */ - quit(message) { - this.bot.send(`QUIT :${message}`); + async quit(message) { + await this.bot.send(`QUIT :${message}`); } /** * @param {string} user * @param {string} message */ - ctcp(user, message) { - this.privmsg(user, `\x01${message}\x01\x01`); + async ctcp(user, message) { + await this.privmsg(user, `\x01${message}\x01\x01`); } } From bce9f76e3ef50e7d2fbdde716a08eda94ebc506c Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Fri, 2 Mar 2018 18:29:37 -0500 Subject: [PATCH 2/7] Async updates --- core.js | 6 ++++-- utils/plugins.js | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core.js b/core.js index 1b39cc3..a282ab3 100644 --- a/core.js +++ b/core.js @@ -350,8 +350,10 @@ class Core { * @param {string} message - The message you want to send */ async immediateSend(message) { - this.socket.write(`${message}\r\n`); - log.debug('[SENT] %s', strip_formatting(message)); + const { promisify } = require('util'); + + await promisify(this.socket.write(`${message}\r\n`)); + await log.debug('[SENT] %s', strip_formatting(message)); } } diff --git a/utils/plugins.js b/utils/plugins.js index 25db2f5..45a565b 100644 --- a/utils/plugins.js +++ b/utils/plugins.js @@ -214,14 +214,14 @@ class Plugins { * @param {ConnectionWrapper} irc * @param {array} args */ - call_command(event, irc, args) { + async call_command(event, irc, args) { irc.send = this.bot._send; if (this.commands[args[0]] !== undefined) { try { let cmd = this.commands[args[0]]; let { perms, min_args } = cmd.opts; - if (check_perms(this.bot.config, event.source.host, event.target, perms)) { + if (await check_perms(this.bot.config, event.source.host, event.target, perms)) { if (args.length >= min_args) { cmd(this.bot, event, irc, args.slice(1)); } else { From 7f8653b84db7948c5bbbd5a9dea281e2c4bbac51 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 26 Mar 2018 09:50:02 -0400 Subject: [PATCH 3/7] Make more stuff asnc functions --- core.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core.js b/core.js index a282ab3..98460db 100644 --- a/core.js +++ b/core.js @@ -46,9 +46,9 @@ class Core { log.error(event.arguments.join(' ')); }; - this.on_ping = irc => { + this.on_ping = async irc => { // Respond to ping event - this.send('PONG'); + await this.send('PONG'); }; this.on_nicknameinuse = async (irc, event) => { @@ -58,7 +58,7 @@ class Core { this.on_welcome = async (irc, event) => { Object.keys(this.config.channels).forEach(channel => { - irc.join(channel, this.config.channels[channel].key); + await irc.join(channel, this.config.channels[channel].key); }); }; @@ -79,9 +79,9 @@ class Core { }); } - this.send(`WHO ${event.target} nuhs%nhuacr`); - this.send(`NAMES ${event.target}`); - irc.mode(event.target, '', ''); // Get modes for the DB + await this.send(`WHO ${event.target} nuhs%nhuac`); + await this.send(`NAMES ${event.target}`); + await irc.mode(event.target, '', ''); // Get modes for the DB } else { // Extended join methods if (args.length > 0) { @@ -89,10 +89,10 @@ class Core { let hostmask = event.source.userhost; let account = args[0] !== '*' ? args[0] : null; - this.state.channels.add_entry(channel, nick, hostmask, account); + await this.state.channels.add_entry(channel, nick, hostmask, account); } - this.send(`WHO ${event.source.nick} nuhs%nhuacr`); + await this.send(`WHO ${event.source.nick} nuhs%nhuacr`); this.nextWHOChannel = event.target; } }; @@ -243,7 +243,7 @@ class Core { udb.seen.sort((a, b) => a.time > b.time); udb.seen = udb.seen.slice(-5); } else { - this.send(`WHO ${event.target} nuhs%nhuacr`); + await this.send(`WHO ${event.target} nuhs%nhuacr`); } }; @@ -260,7 +260,7 @@ class Core { result = this.ctcp[ctcp_message]; } - irc.notice(event.source.nick, `${ctcp_message} ${result}`); + await irc.notice(event.source.nick, `${ctcp_message} ${result}`); } } }; From 2479a159a9269a70d8b17ac93eeba5107948324c Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Mon, 26 Mar 2018 09:54:36 -0400 Subject: [PATCH 4/7] Fix some errors --- core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core.js b/core.js index 98460db..7767167 100644 --- a/core.js +++ b/core.js @@ -57,7 +57,7 @@ class Core { }; this.on_welcome = async (irc, event) => { - Object.keys(this.config.channels).forEach(channel => { + Object.keys(this.config.channels).forEach(async channel => { await irc.join(channel, this.config.channels[channel].key); }); }; @@ -176,7 +176,7 @@ class Core { this.on_cap = async (irc, event) => this.caps.handler(event); - this.on_authenticate = async (irc, event) => this.sasl.on_authenticate(event); + this.on_authenticate = async (irc, event) => await this.sasl.on_authenticate(event); this.on_saslfailed = async (irc, event) => this.sasl.on_saslfailed(event); From 1f627f518f1ccd88f49b3d5a93a327fc9f5264c5 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Tue, 22 May 2018 18:59:39 -0400 Subject: [PATCH 5/7] Async functions more stuff --- utils/database.js | 10 +++++----- utils/flood-protection.js | 8 ++++---- utils/plugins.js | 6 +++--- wrappers.js | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/utils/database.js b/utils/database.js index 89bc561..b47fe93 100644 --- a/utils/database.js +++ b/utils/database.js @@ -19,7 +19,7 @@ class ChannelDB extends dict { this[irc] = wrappers; } - change_attr(name, attr, value, channel=null) { + async change_attr(name, attr, value, channel=null) { if (channel !== null) { this[channel].users[name][attr] = value; } else { @@ -33,7 +33,7 @@ class ChannelDB extends dict { } } - remove_entry(event, nick) { + async remove_entry(event, nick) { try { delete this[event.target].users[nick]; } catch (e) { @@ -46,7 +46,7 @@ class ChannelDB extends dict { } } - add_entry(channel, nick, hostmask, account, realname) { + async add_entry(channel, nick, hostmask, account, realname) { let temp = { hostmask, host: hostmask.split('@')[1], @@ -66,7 +66,7 @@ class ChannelDB extends dict { } } - get_user_host(channel, nick) { + async get_user_host(channel, nick) { let host; try { @@ -79,7 +79,7 @@ class ChannelDB extends dict { return host; } - flush() { + async flush() { fs.writeFile('userdb.json', JSON.stringify(this, null, 2) + '\n', err => { if (err) { log.error('An error was thrown while writing the user DB'); diff --git a/utils/flood-protection.js b/utils/flood-protection.js index b7e348e..d311416 100644 --- a/utils/flood-protection.js +++ b/utils/flood-protection.js @@ -33,7 +33,7 @@ class FloodProtection { } /** Deletes all messages except those that aren't set by plugins **/ - flushAll() { + async flushAll() { this.bot.sendQueue = this.bot.sendQueue.filter(element => !element.root); } @@ -41,7 +41,7 @@ class FloodProtection { * Flush messages for a target * @param {string} target **/ - flushTarget(target) { + async flushTarget(target) { this.bot.sendQueue = this.bot.sendQueue.filter(e => e.target !== target && e.root); } @@ -50,7 +50,7 @@ class FloodProtection { * @param {string} message * @return {string} **/ - getTarget(message) { + async getTarget(message) { if (!message) return; let splitMessage = message.split(' '); @@ -61,7 +61,7 @@ class FloodProtection { * @func * @param {object} that **/ - reduceQueue(that) { + async reduceQueue(that) { if (that.bot.sendQueue.length === 0) { that.canBurst = true; } else if (that.canBurst) { diff --git a/utils/plugins.js b/utils/plugins.js index 45a565b..4b7fe08 100644 --- a/utils/plugins.js +++ b/utils/plugins.js @@ -24,7 +24,7 @@ class Hooks { * @param {Object} hookStore An object mapping hooks * @param {Array} args An array in the format [message, hook (callback funct)] */ - addHook(hookStore, args) { + async addHook(hookStore, args) { // Test if hooks already exist if (Object.keys(hookStore).includes(args[0])) { hookStore[args[0]].push(args[1]); @@ -171,7 +171,7 @@ class Plugins { * @func * @param {function} cmd */ - set_defaults(cmd) { + async set_defaults(cmd) { let opts = cmd.opts; opts.restrictions = getDefault(opts, 'restrictions', {}); @@ -201,7 +201,7 @@ class Plugins { * @param {string} name * @param {function} func */ - add_cmd(name, func) { + async add_cmd(name, func) { this.commands[name] = func; for (let alias of func.opts.aliases) { this.commands[alias] = func; diff --git a/wrappers.js b/wrappers.js index ae6a219..8f7997d 100644 --- a/wrappers.js +++ b/wrappers.js @@ -17,7 +17,7 @@ class ConnectionWrapper { * @func * @param {string} message - Message being sent to server */ - send(message) { + async send(message) { this.bot.send(message); } From 5d450fa0eb530a112fbb3fa66c4703b01af9bfad Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Sun, 3 Jun 2018 16:28:00 -0400 Subject: [PATCH 6/7] Make send async --- utils/flood-protection.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/flood-protection.js b/utils/flood-protection.js index d311416..4c5a2e5 100644 --- a/utils/flood-protection.js +++ b/utils/flood-protection.js @@ -19,7 +19,7 @@ class FloodProtection { * @func * @param {string} message - Message to send (non-flushable) **/ - this.bot.send = message => { + this.bot.send = async message => { this.bot.sendQueue.push({ content: message, root: true, target: this.getTarget(message) }); }; From 3d53cdb6da61e5314c374ab66a0cacd4fe443d93 Mon Sep 17 00:00:00 2001 From: wolfy1339 Date: Fri, 8 Jun 2018 10:42:07 -0400 Subject: [PATCH 7/7] async some of these functions --- utils/flood-protection.js | 2 +- utils/plugins.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/flood-protection.js b/utils/flood-protection.js index 4c5a2e5..b56a08e 100644 --- a/utils/flood-protection.js +++ b/utils/flood-protection.js @@ -27,7 +27,7 @@ class FloodProtection { * @func * @param {string} message - Message to send from plugin (flushable) **/ - this.bot._send = message => { + this.bot._send = async message => { this.bot.sendQueue.push({ content: message, root: false, target: this.getTarget(message) }); }; } diff --git a/utils/plugins.js b/utils/plugins.js index 4b7fe08..4c92269 100644 --- a/utils/plugins.js +++ b/utils/plugins.js @@ -126,7 +126,7 @@ class Hooks { * @param {*} def Default value if key is not found * @return {*} */ -function getDefault(object, key, def) { +async function getDefault(object, key, def) { return object[key] !== undefined ? object[key] : def; }