diff --git a/package-lock.json b/package-lock.json index 12d7982..4fe0f12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,7 +14,7 @@ "connect-mongo": "^3.2.0", "convert-units": "^2.3.4", "dotenv": "^16.3.1", - "eris": "^0.17.0", + "eris": "^0.17.2", "express-session": "^1.17.0", "mongodb": "^3.5.5", "node-fetch": "^2.6.7", @@ -1431,9 +1431,9 @@ } }, "node_modules/eris": { - "version": "0.17.0", - "resolved": "https://registry.npmjs.org/eris/-/eris-0.17.0.tgz", - "integrity": "sha512-ba7fpe104uw86z8fbX7V1ORMblB7jMJoDsRpiy8BKDQo+kNCRuUXB5xfg/VKGtZ944QroBTEZDuyXCBhKOBplQ==", + "version": "0.17.2", + "resolved": "https://registry.npmjs.org/eris/-/eris-0.17.2.tgz", + "integrity": "sha512-OzffDSL81VooFXfRn56ienSg7J6fagoN8WdkmCHjn0B9a4jUA3bVouMztQiaXT54jHV5jaX9D0mJ/b9/0mFoVg==", "dependencies": { "ws": "^8.2.3" }, @@ -5335,9 +5335,9 @@ "integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==" }, "eris": { - "version": "0.17.0", - "resolved": "https://registry.npmjs.org/eris/-/eris-0.17.0.tgz", - "integrity": "sha512-ba7fpe104uw86z8fbX7V1ORMblB7jMJoDsRpiy8BKDQo+kNCRuUXB5xfg/VKGtZ944QroBTEZDuyXCBhKOBplQ==", + "version": "0.17.2", + "resolved": "https://registry.npmjs.org/eris/-/eris-0.17.2.tgz", + "integrity": "sha512-OzffDSL81VooFXfRn56ienSg7J6fagoN8WdkmCHjn0B9a4jUA3bVouMztQiaXT54jHV5jaX9D0mJ/b9/0mFoVg==", "requires": { "opusscript": "^0.0.8", "tweetnacl": "^1.0.3", diff --git a/package.json b/package.json index 9ee0532..fb1418e 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "connect-mongo": "^3.2.0", "convert-units": "^2.3.4", "dotenv": "^16.3.1", - "eris": "^0.17.0", + "eris": "^0.17.2", "express-session": "^1.17.0", "mongodb": "^3.5.5", "node-fetch": "^2.6.7", diff --git a/src/bot/commands/misc/avatar.js b/src/bot/commands/misc/avatar.js index 5795d1d..93726ed 100644 --- a/src/bot/commands/misc/avatar.js +++ b/src/bot/commands/misc/avatar.js @@ -7,18 +7,18 @@ function resizeAvatarURL (url, size) { return `${url.split('?size=')[0]}?size=${size}`; } -const command = new Command('avatar', async (msg, args) => { +const command = new Command('avatar', async (msg, args, {sendMessage}) => { if (args.length === 0) { - msg.channel.createMessage(resizeAvatarURL(msg.member.avatarURL, AVATAR_IMAGE_SIZE)).catch(() => {}); + sendMessage(msg, resizeAvatarURL(msg.member.avatarURL, AVATAR_IMAGE_SIZE)).catch(() => {}); return; } const [member] = await parseGuildMember(args.join(' '), msg.channel.guild, msg.member); if (!member) { - msg.channel.createMessage('Member not found, check if what you\'re using is correct or try using an ID.').catch(() => {}); + sendMessage(msg, 'Member not found, check if what you\'re using is correct or try using an ID.').catch(() => {}); return; } - msg.channel.createMessage(resizeAvatarURL(member.avatarURL, AVATAR_IMAGE_SIZE)).catch(() => {}); + sendMessage(msg, resizeAvatarURL(member.avatarURL, AVATAR_IMAGE_SIZE)).catch(() => {}); }); command.help = { args: '[user]', diff --git a/src/bot/commands/misc/convert.js b/src/bot/commands/misc/convert.js index 85fa9cf..f33a3ff 100644 --- a/src/bot/commands/misc/convert.js +++ b/src/bot/commands/misc/convert.js @@ -153,7 +153,7 @@ const command = new Command('convert', async (msg, args, context) => { } } - msg.channel.createMessage(message).catch(() => {}); + context.sendMessage(msg, message).catch(() => {}); }); command.help = { args: '[amount] ', diff --git a/src/bot/commands/misc/defaultavatar.js b/src/bot/commands/misc/defaultavatar.js index d9c83a3..3dde272 100644 --- a/src/bot/commands/misc/defaultavatar.js +++ b/src/bot/commands/misc/defaultavatar.js @@ -3,18 +3,18 @@ import {Command} from 'yuuko'; import {AVATAR_IMAGE_SIZE, parseUser} from '../../util/discord'; -const command = new Command('defaultavatar', async (msg, args) => { +const command = new Command('defaultavatar', async (msg, args, {sendMessage}) => { if (args.length === 0) { - msg.channel.createMessage(msg.author.dynamicAvatarURL('', AVATAR_IMAGE_SIZE)).catch(() => {}); + sendMessage(msg, msg.author.dynamicAvatarURL('', AVATAR_IMAGE_SIZE)).catch(() => {}); return; } const [user] = await parseUser(args.join(' '), msg.channel.guild, msg.author); if (!user) { - msg.channel.createMessage('Member not found, check if what you\'re using is correct or try using an ID.').catch(() => {}); + sendMessage(msg, 'Member not found, check if what you\'re using is correct or try using an ID.').catch(() => {}); return; } - msg.channel.createMessage(user.dynamicAvatarURL('', AVATAR_IMAGE_SIZE)).catch(() => {}); + sendMessage(msg, user.dynamicAvatarURL('', AVATAR_IMAGE_SIZE)).catch(() => {}); }); command.help = { args: '[user]', diff --git a/src/bot/commands/misc/joke.js b/src/bot/commands/misc/joke.js index 9d68f16..5373a21 100644 --- a/src/bot/commands/misc/joke.js +++ b/src/bot/commands/misc/joke.js @@ -4,16 +4,16 @@ import {Command} from 'yuuko'; import fetch from 'node-fetch'; -const command = new Command('joke', async msg => { +const command = new Command('joke', async (msg, _, {sendMessage}) => { try { const res = await fetch('https://official-joke-api.appspot.com/random_joke'); if (res.status !== 200) { throw new Error('Error getting joke.'); } const joke = await res.json(); - msg.channel.createMessage(`${joke.setup}\n${joke.punchline}`); + sendMessage(msg, `${joke.setup}\n${joke.punchline}`); } catch (err) { - msg.channel.createMessage(err.message).catch(() => {}); + sendMessage(msg, err.message).catch(() => {}); } }); command.help = { diff --git a/src/bot/commands/misc/pick.js b/src/bot/commands/misc/pick.js index 6b4f0d6..cada336 100644 --- a/src/bot/commands/misc/pick.js +++ b/src/bot/commands/misc/pick.js @@ -16,7 +16,7 @@ const command = new Command('pick', (msg, args, context) => { // We use a comma as a separator for each choice const choices = args.join(' ').split(',').map(str => str.trim()); - msg.channel.createMessage(`I pick **${choices[getRandomInt(0, choices.length - 1)]}**`).catch(() => {}); + context.sendMessage(msg, `I pick **${choices[getRandomInt(0, choices.length - 1)]}**`).catch(() => {}); }); command.help = { args: ', , ', diff --git a/src/bot/commands/misc/roll.js b/src/bot/commands/misc/roll.js index 1c01145..9fdd7c0 100644 --- a/src/bot/commands/misc/roll.js +++ b/src/bot/commands/misc/roll.js @@ -8,7 +8,7 @@ function getRandomInt (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } -const command = new Command('roll', (msg, args) => { +const command = new Command('roll', (msg, args, {sendMessage}) => { let min = 0; let max = 6; @@ -18,9 +18,9 @@ const command = new Command('roll', (msg, args) => { } if (isNaN(min) || isNaN(max)) { - msg.channel.createMessage('Please enter a valid number!').catch(() => {}); + sendMessage(msg, 'Please enter a valid number!').catch(() => {}); } else { - msg.channel.createMessage(`You rolled a ${getRandomInt(min, max)}`).catch(() => {}); + sendMessage(msg, `You rolled a ${getRandomInt(min, max)}`).catch(() => {}); } }); command.help = { diff --git a/src/bot/commands/ping.js b/src/bot/commands/ping.js index 34680f4..3c67237 100644 --- a/src/bot/commands/ping.js +++ b/src/bot/commands/ping.js @@ -30,7 +30,7 @@ if (!gitRepoURI) { }); } -const command = new Command('ping', async (msg, args, {prefix, client}) => { +const command = new Command('ping', async (msg, args, {prefix, client, sendMessage}) => { let messageContent = 'Pong!'; if (commitHash != null) { messageContent += `\nCommit: ${commitHash}`; @@ -43,7 +43,7 @@ const command = new Command('ping', async (msg, args, {prefix, client}) => { messageContent += `\nUse \`${prefix.match(client.mentionPrefixRegExp) ? '' : prefix}help\` for a list of commands.`; const then = Date.now(); - const newMsg = await msg.channel.createMessage(messageContent); + const newMsg = await sendMessage(msg, messageContent); newMsg.edit(newMsg.content.replace('Pong!', `Pong! (${Date.now() - then}ms REST round-trip)`)); }); command.help = { diff --git a/src/bot/commands/reminders/remind.js b/src/bot/commands/reminders/remind.js index e533cfa..9074df4 100644 --- a/src/bot/commands/reminders/remind.js +++ b/src/bot/commands/reminders/remind.js @@ -80,7 +80,7 @@ const command = new Command(['remind', 'remindme'], async (message, args, contex } // Send confirmation, throw away any possible errors - message.channel.createMessage(`Will remind you ${formatDateRelative(due)}.`).catch(() => {}); + context.sendMessage(message, `Will remind you ${formatDateRelative(due)}.`).catch(() => {}); }); command.help = { desc: "Sets a reminder that you'll get pinged for in the future.", diff --git a/src/bot/index.js b/src/bot/index.js index af2f795..0729c46 100644 --- a/src/bot/index.js +++ b/src/bot/index.js @@ -52,6 +52,14 @@ export default (mongoClient, db) => { }, }); + // Another helper for sending messages because discord is wack and stopped + // giving us DM channel objects to send messages in + bot.extendContext({ + sendMessage (msg, ...args) { + return bot.createMessage(msg.channel.id, ...args); + }, + }); + // Connect the bot to Discord bot.connect();