Browse Source

Don't fail on reply

ghorsington 2 years ago
parent
commit
38c5bd7bdf

+ 1 - 1
bot/src/plugin_manager.ts

@@ -130,7 +130,7 @@ export class PluginManager {
 
             if (match) {
                 if (!c.allowDM && m.channel.type == "DM") {
-                    await tryDo(m.reply("Sorry, this command is not available in DMs for now."));
+                    await tryDo(m.reply({ content: "Sorry, this command is not available in DMs for now.", failIfNotExists: false }));
                     return false;
                 }
                 if (c.auth && !(await isAuthorisedAsync(m.member)))

+ 1 - 1
bot/src/plugins/facemorph.ts

@@ -261,7 +261,7 @@ export class Facemorph {
             .filter(v => !v.msg.author.bot && v.att != undefined).last() as AttachedMessage;
 
         if (!lastImagedMessage) {
-            msg.reply("sorry, I couldn't find any recent messages with images.");
+            msg.reply({ content: "sorry, I couldn't find any recent messages with images.", failIfNotExists: false });
             return;
         }
 

+ 2 - 2
bot/src/plugins/forums_news_checker.ts

@@ -317,14 +317,14 @@ React with ✅ (approve) or ❌ (deny).`;
         });
 
         if (!post || !post.verifyMessage) {
-            message.reply(`no unapproved news items with id ${id}!`);
+            message.reply({ content: `no unapproved news items with id ${id}!`, failIfNotExists: false });
             return;
         }
 
         const editMsg = await this.tryFetchMessage(client.bot.channels.resolve(this.verifyChannelId) ?? undefined, post.verifyMessage.messageId);
 
         if (!editMsg) {
-            message.reply(`no verify message found for ${id}! This is a bug: report to horse.`);
+            message.reply({ content: `no verify message found for ${id}! This is a bug: report to horse.`, failIfNotExists: false });
             return;
         }
 

+ 11 - 7
bot/src/plugins/guide.ts

@@ -111,12 +111,12 @@ export class GuideCommands {
         const msgContents = match[4].trim();
 
         if (msgContents.length == 0) {
-            message.reply("the guide must have some content!");
+            message.reply({ content: "the guide must have some content!", failIfNotExists: false});
             return;
         }
         
         if (!(<string[]>Object.values(GuideType)).includes(type)) {
-            message.reply(`the type ${type} is not a valid guide type!`);
+            message.reply({ content: `the type ${type} is not a valid guide type!`, failIfNotExists: false});
             return;
         }
 
@@ -168,9 +168,10 @@ export class GuideCommands {
         } else
             await addGuide();
 
-        message.reply(
-            `Added/updated "${name}" (keywords \`${keywords.join(" ")}\`)!`
-        );
+        message.reply({
+            content: `Added/updated "${name}" (keywords \`${keywords.join(" ")}\`)!`,
+            failIfNotExists: false
+        });
     }
 
     @Command({
@@ -210,12 +211,15 @@ export class GuideCommands {
 
             if (guideKeywordsCount == dedupedKeywords.length) {
                 await guideRepo.delete({ id: existingGuide.id });
-                await message.reply(`removed ${type} "${keywords.join(" ")}"!`);
+                await message.reply({ content: `removed ${type} "${keywords.join(" ")}"!`, failIfNotExists: false});
                 return;
             }
         }
 
-        await message.reply(`no such ${type} with keywords \`${keywords.join(" ")}\`! Did you forget to specify all keywords?`);
+        await message.reply({
+            content: `no such ${type} with keywords \`${keywords.join(" ")}\`! Did you forget to specify all keywords?`,
+            failIfNotExists: false
+        });
     }
 
     @Command({

+ 1 - 1
bot/src/plugins/help.ts

@@ -43,6 +43,6 @@ export class Help {
                 return;
         }
 
-        message.reply(msg);
+        message.reply({ content: msg, failIfNotExists: false });
     }
 }

+ 2 - 2
bot/src/plugins/inspire.ts

@@ -17,7 +17,7 @@ export class Inspire {
         const result = await tryDo(got.get("https://inspirobot.me/api?generate=true"));
         if(!result.ok) {
             logger.error("Failed to get inspiration, error %s", result.error);
-            await message.reply("sorry, couldn't get inspiration :(.");
+            await message.reply({ content: "sorry, couldn't get inspiration :(.", failIfNotExists: false });
             return;
         }
 
@@ -27,7 +27,7 @@ export class Inspire {
         }));
         if (!messagePostResult.ok) {
             logger.error("Failed to get inspiration, error %s", messagePostResult.error);
-            await message.reply("sorry, couldn't get inspiration :(.");
+            await message.reply({ content: "sorry, couldn't get inspiration :(.", failIfNotExists: false });
         }
     }
 }

+ 5 - 5
bot/src/plugins/quote.ts

@@ -39,7 +39,7 @@ export class QuoteCommand {
             message: msg
         }));
 
-        message.reply(`added quote (ID: ${newQuote.id})!`);
+        message.reply({ content: `added quote (ID: ${newQuote.id})!`, failIfNotExists: false});
     }
 
     @Command({
@@ -59,7 +59,7 @@ export class QuoteCommand {
                                                 limit 1`) as Quote[];
 
         if (quotes.length == 0) {
-            message.reply("I have no quotes!");
+            message.reply({ content: "I have no quotes!", failIfNotExists: false });
             return;
         }
 
@@ -88,7 +88,7 @@ export class QuoteCommand {
         if (res.affected == 0)
             return;
 
-        message.reply(`removed quote #${val}!`);
+        message.reply({ content: `removed quote #${val}!`, failIfNotExists: false });
     }
 
     @Command({
@@ -106,11 +106,11 @@ export class QuoteCommand {
         const quotes = await repo.find();
 
         if (quotes.length == 0) {
-            message.reply("I have no quotes!");
+            message.reply({ content: "I have no quotes!", failIfNotExists: false });
             return;
         }
 
         const quotesListing = quotes.reduce((p, c) => `${p}[${c.id}] "${this.minify(c.message, 10)}" by ${c.author}\n`, "\n");
-        message.reply(`I know the following quotes:\n\`\`\`${quotesListing}\`\`\``);
+        message.reply({ content: `I know the following quotes:\n\`\`\`${quotesListing}\`\`\``, failIfNotExists: false });
     }
 }

+ 1 - 1
bot/src/plugins/rcg.ts

@@ -16,7 +16,7 @@ export class Rcg {
     async sendErrorMessage(msg: Message): Promise<void> {
         const xkcdResult = await tryDo(got.get<XkcdResponse>("https://xkcd.com/info.0.json", { responseType: "json" }));
         if(!xkcdResult.ok || !xkcdResult.result) {
-            await msg.reply("sorry, I couldn't get any comics :(.");
+            await msg.reply({ content: "sorry, I couldn't get any comics :(.", failIfNotExists: false });
             return;
         }
         await msg.reply({

+ 5 - 5
bot/src/plugins/react.ts

@@ -60,7 +60,7 @@ export class ReactCommands {
             const reactionEmoji = reactContents[2];
 
             if (!client.bot.emojis.cache.has(reactionEmoji)) {
-                message.reply("I cannot react with this emoji :(");
+                message.reply({ content: "I cannot react with this emoji :(", failIfNotExists: false });
                 return;
             }
 
@@ -72,7 +72,7 @@ export class ReactCommands {
             });
             await repo.save(msgReaction);
 
-            message.reply("added reaction!");
+            message.reply({ content: "added reaction!", failIfNotExists: false });
         }
     }
 
@@ -91,10 +91,10 @@ export class ReactCommands {
         const result = await repo.delete({ message: content });
 
         if (result.affected == 0) {
-            message.reply("no such reaction available!");
+            message.reply({ content: "no such reaction available!", failIfNotExists: false });
             return;
         }
-        message.reply("removed reaction!");
+        message.reply({ content: "removed reaction!", failIfNotExists: false });
     }
 
     @Command({
@@ -113,7 +113,7 @@ export class ReactCommands {
         });
 
         const reactions = messages.reduce((p, c) => `${p}\n${c.message}`, "");
-        message.reply(`I'll react to the following messages:\n\`\`\`${reactions}\n\`\`\``);
+        message.reply({ content: `I'll react to the following messages:\n\`\`\`${reactions}\n\`\`\``, failIfNotExists: false });
     }
 
     @Event("message")

+ 15 - 15
bot/src/plugins/violation.ts

@@ -214,30 +214,30 @@ export class ViolationPlugin {
 
     private async removeTimedViolation<T extends TimedViolation>(type: ObjectType<T>, message: Message, command = "violation") {
         if (!message.guild) {
-            await message.reply("cannot do in DMs!");
+            await message.reply({ content: "cannot do in DMs!", failIfNotExists: false });
             return;
         }
 
         const settingsRepo = getRepository(GuildViolationSettings);
         const settings = await settingsRepo.findOne(message.guild.id);
         if (!settings) {
-            message.reply("this guild doesn't have violation settings set up!");
+            message.reply({ content: "this guild doesn't have violation settings set up!", failIfNotExists: false });
             return;
         }
 
         const [, userId] = parseArgs(message.content);
         if (!userId) {
-            await message.reply("no user specified!");
+            await message.reply({ content: "no user specified!", failIfNotExists: false });
             return;
         }
         if (userId == message.author.id) {
-            await message.reply(`cannot ${command} yourself!`);
+            await message.reply({ content: `cannot ${command} yourself!`, failIfNotExists: false });
             return;
         }
 
         const user = await this.resolveUser(userId);
         if (!user) {
-            await message.reply("couldn't find the given user!");
+            await message.reply({ content: "couldn't find the given user!", failIfNotExists: false });
             logger.error("Tried to un-%s user %s but couldn't find them by id!", command, userId);
             return;
         }
@@ -251,7 +251,7 @@ export class ViolationPlugin {
             }
         });
         if (!existingViolation) {
-            await message.reply(`user has no existing active ${command}s in the DB!`);
+            await message.reply({ content: `user has no existing active ${command}s in the DB!`, failIfNotExists: false });
             return;
         }
 
@@ -260,7 +260,7 @@ export class ViolationPlugin {
 
         const handler = this.getViolationHandler(type);
         await handler.stop(message.guild, user.id, settings, existingViolation);
-        await message.reply(`removed ${command} on user!`);
+        await message.reply({ content: `removed ${command} on user!`, failIfNotExists: false });
     }
 
     private async applyTimedViolation<T extends TimedViolation>(type: ObjectType<T>, info: ViolationInfo, command = "violation", apply: StartViolationFunction, remove: StopViolationFunction, modify?: ModifyViolationFunction) {
@@ -355,14 +355,14 @@ export class ViolationPlugin {
 
     private async parseCommand(message: Message, command = "violation"): Promise<Option<ViolationInfo>> {
         if (!message.guild) {
-            await message.reply("cannot do in DMs!");
+            await message.reply({ content: "cannot do in DMs!", failIfNotExists: false });
             return { ok: false };
         }
         const violationSettingsRepo = getRepository(GuildViolationSettings);
         const settings = await violationSettingsRepo.findOne(message.guild.id);
 
         if (!settings) {
-            await message.reply("sorry, this server doesn't have violation settings set up.");
+            await message.reply({ content: "sorry, this server doesn't have violation settings set up.", failIfNotExists: false });
             logger.error(
                 "%s was called in guild %s (%s) on user %s which doesn't have config set up!",
                 command,
@@ -378,37 +378,37 @@ export class ViolationPlugin {
         const noAnnounce = directive.endsWith("!");
 
         if (!userId) {
-            await message.reply("no user specified!");
+            await message.reply({ content: "no user specified!", failIfNotExists: false });
             return { ok: false };
         }
 
         const user = await this.resolveUser(userId);
 
         if (!user) {
-            await message.reply("couldn't find the given user!");
+            await message.reply({ content: "couldn't find the given user!", failIfNotExists: false });
             logger.error("Tried to %s user %s but couldn't find them by id!", command, userId);
             return { ok: false };
         }
 
         if (user.id == message.author.id) {
-            await message.reply(`cannot ${command} yourself!`);
+            await message.reply({ content: `cannot ${command} yourself!`, failIfNotExists: false });
             return { ok: false };
         }
 
         if (user.id == client.botUser.id) {
-            await message.reply(`cannot apply ${command} on me!`);
+            await message.reply({ content: `cannot apply ${command} on me!`, failIfNotExists: false });
             return { ok: false };
         }
 
         const memberResolve = await tryDo(message.guild.members.fetch(user));
         if (!memberResolve.ok) {
-            await message.reply("user is not member of the server anymore!");
+            await message.reply({ content: "user is not member of the server anymore!", failIfNotExists: false });
             logger.error("Tried to %s user %s but they are not on the server anymore!", command, userId);
             return { ok: false };
         }
 
         if (await isAuthorisedAsync(memberResolve.result)) {
-            await message.reply(`cannot apply ${command} on another moderator!`);
+            await message.reply({ content: `cannot apply ${command} on another moderator!`, failIfNotExists: false });
             return { ok: false };
         }