Fix error when removing reactions on a deleted message

This commit is contained in:
Ske 2020-01-03 14:02:25 +01:00
parent c89802a21c
commit 8b65754b00

View File

@ -1,9 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Discord.Net;
using Discord.WebSocket; using Discord.WebSocket;
using PluralKit.Bot.CommandSystem; using PluralKit.Bot.CommandSystem;
@ -71,6 +73,8 @@ namespace PluralKit.Bot {
return eb.Build(); return eb.Build();
} }
try
{
var msg = await ctx.Channel.SendMessageAsync(embed: MakeEmbedForPage(0)); var msg = await ctx.Channel.SendMessageAsync(embed: MakeEmbedForPage(0));
if (pageCount == 1) return; // If we only have one page, don't bother with the reaction/pagination logic, lol if (pageCount == 1) return; // If we only have one page, don't bother with the reaction/pagination logic, lol
var botEmojis = new[] { new Emoji("\u23EA"), new Emoji("\u2B05"), new Emoji("\u27A1"), new Emoji("\u23E9"), new Emoji(Emojis.Error) }; var botEmojis = new[] { new Emoji("\u23EA"), new Emoji("\u2B05"), new Emoji("\u27A1"), new Emoji("\u23E9"), new Emoji(Emojis.Error) };
@ -101,9 +105,13 @@ namespace PluralKit.Bot {
// "escape hatch", clean up as if we hit X // "escape hatch", clean up as if we hit X
} }
if (await ctx.HasPermission(ChannelPermission.ManageMessages)) await msg.RemoveAllReactionsAsync(); if (await ctx.HasPermission(ChannelPermission.ManageMessages)) await msg.RemoveAllReactionsAsync();
else await msg.RemoveReactionsAsync(ctx.Shard.CurrentUser, botEmojis); else await msg.RemoveReactionsAsync(ctx.Shard.CurrentUser, botEmojis);
} }
// If we get a "NotFound" error, the message has been deleted and thus not our problem
catch (HttpException e) when (e.HttpCode == HttpStatusCode.NotFound) { }
}
public static async Task<T> Choose<T>(this Context ctx, string description, IList<T> items, Func<T, string> display = null) public static async Task<T> Choose<T>(this Context ctx, string description, IList<T> items, Func<T, string> display = null)
{ {