|
@@ -6,6 +6,7 @@ import { Message, User, PartialUser, MessageReaction as DiscordMessageReaction }
|
|
import { logger } from "src/logging";
|
|
import { logger } from "src/logging";
|
|
import { Command, ICommandData, Event, BotEventData, Plugin } from "src/model/plugin";
|
|
import { Command, ICommandData, Event, BotEventData, Plugin } from "src/model/plugin";
|
|
import { MessageReaction } from "@shared/db/entity/MessageReaction";
|
|
import { MessageReaction } from "@shared/db/entity/MessageReaction";
|
|
|
|
+import { tryDo } from "@shared/common/async_utils";
|
|
|
|
|
|
const pattern = /^react to\s+"([^"]+)"\s+with\s+<:[^:]+:([^>]+)>$/i;
|
|
const pattern = /^react to\s+"([^"]+)"\s+with\s+<:[^:]+:([^>]+)>$/i;
|
|
|
|
|
|
@@ -33,8 +34,12 @@ export class ReactCommands {
|
|
@Event("messageReactionAdd")
|
|
@Event("messageReactionAdd")
|
|
async randomReact(data: BotEventData, reaction: DiscordMessageReaction, user: User | PartialUser): Promise<void> {
|
|
async randomReact(data: BotEventData, reaction: DiscordMessageReaction, user: User | PartialUser): Promise<void> {
|
|
if (Math.random() <= this.REACT_PROBABILITY && !user.bot) {
|
|
if (Math.random() <= this.REACT_PROBABILITY && !user.bot) {
|
|
- logger.verbose(`Reacting to message ${reaction.message.id} because user ${user.tag} reacted to it`);
|
|
|
|
- reaction.message.react(reaction.emoji);
|
|
|
|
|
|
+ const msg = reaction.message;
|
|
|
|
+ logger.verbose(`Reacting to message ${msg.id} because user ${user.tag} reacted to it`);
|
|
|
|
+ const result = await tryDo(msg.react(reaction.emoji));
|
|
|
|
+ if (!result.ok) {
|
|
|
|
+ logger.error("Failed to react to user %s#%s (%s): %s", msg.author.username, msg.author.discriminator, msg.author.id, result.error);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -126,8 +131,12 @@ export class ReactCommands {
|
|
|
|
|
|
if (message) {
|
|
if (message) {
|
|
const emoji = client.bot.emojis.resolve(message.reactionEmoteId);
|
|
const emoji = client.bot.emojis.resolve(message.reactionEmoteId);
|
|
- if (emoji)
|
|
|
|
- msg.react(emoji);
|
|
|
|
|
|
+ if (emoji) {
|
|
|
|
+ const result = await tryDo(msg.react(emoji));
|
|
|
|
+ if (!result.ok) {
|
|
|
|
+ logger.error("Failed to react to user %s#%s (%s): %s", msg.author.username, msg.author.discriminator, msg.author.id, result.error);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
data.actionsDone = true;
|
|
data.actionsDone = true;
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -161,8 +170,12 @@ export class ReactCommands {
|
|
|
|
|
|
for (const emote of randomEmotes) {
|
|
for (const emote of randomEmotes) {
|
|
const emoji = client.bot.emojis.resolve(emote.reactionId);
|
|
const emoji = client.bot.emojis.resolve(emote.reactionId);
|
|
- if(emoji)
|
|
|
|
- await msg.react(emoji);
|
|
|
|
|
|
+ if(emoji) {
|
|
|
|
+ const result = await tryDo(msg.react(emoji));
|
|
|
|
+ if (!result.ok) {
|
|
|
|
+ logger.error("Failed to react to user %s#%s (%s): %s", msg.author.username, msg.author.discriminator, msg.author.id, result.error);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
data.actionsDone = true;
|
|
data.actionsDone = true;
|