summaryrefslogtreecommitdiff
path: root/packages/gateway/src/commands/say.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/gateway/src/commands/say.ts')
-rw-r--r--packages/gateway/src/commands/say.ts176
1 files changed, 88 insertions, 88 deletions
diff --git a/packages/gateway/src/commands/say.ts b/packages/gateway/src/commands/say.ts
index 31afb04..ec19a33 100644
--- a/packages/gateway/src/commands/say.ts
+++ b/packages/gateway/src/commands/say.ts
@@ -2,124 +2,124 @@ import { Message } from "discord.js";
import { GUILD_ID } from "../constants";
export const handleSayCommand = async (message: Message) => {
- if (message.author.bot) return;
+ if (message.author.bot) return;
- if (message.content.toLowerCase().startsWith("uma!say")) {
- const application = await message.client.application?.fetch();
- const ownerId = application?.owner?.id;
+ if (message.content.toLowerCase().startsWith("uma!say")) {
+ const application = await message.client.application?.fetch();
+ const ownerId = application?.owner?.id;
- if (message.author.id !== ownerId) return;
+ if (message.author.id !== ownerId) return;
- const parameters = message.content.split(" ").slice(1);
+ const parameters = message.content.split(" ").slice(1);
- if (parameters.length < 2) {
- await message.reply(
- "❌ Usage: `uma!say <channel_mention_or_message_id> <message>`\nExamples:\n- `uma!say #general Hello everyone!`\n- `uma!say 1234567890123456789 Thanks for the info!`",
- );
+ if (parameters.length < 2) {
+ await message.reply(
+ "❌ Usage: `uma!say <channel_mention_or_message_id> <message>`\nExamples:\n- `uma!say #general Hello everyone!`\n- `uma!say 1234567890123456789 Thanks for the info!`",
+ );
- return;
- }
+ return;
+ }
- const firstParameter = parameters[0];
- const messageContent = parameters.slice(1).join(" ");
- let targetChannel: any;
- let targetMessage: any = null;
- const messageIdMatch = firstParameter.match(/^\d{17,19}$/);
+ const firstParameter = parameters[0];
+ const messageContent = parameters.slice(1).join(" ");
+ let targetChannel: any;
+ let targetMessage: any = null;
+ const messageIdMatch = firstParameter.match(/^\d{17,19}$/);
- if (messageIdMatch) {
- try {
- const guild = message.client.guilds.cache.get(GUILD_ID);
+ if (messageIdMatch) {
+ try {
+ const guild = message.client.guilds.cache.get(GUILD_ID);
- if (!guild) {
- await message.reply("❌ Guild not found.");
+ if (!guild) {
+ await message.reply("❌ Guild not found.");
- return;
- }
+ return;
+ }
- let foundMessage = null;
+ let foundMessage = null;
- for (const channel of guild.channels.cache.values()) {
- if (channel.isTextBased()) {
- try {
- foundMessage = await channel.messages.fetch(firstParameter);
+ for (const channel of guild.channels.cache.values()) {
+ if (channel.isTextBased()) {
+ try {
+ foundMessage = await channel.messages.fetch(firstParameter);
- if (foundMessage) {
- targetChannel = channel;
- targetMessage = foundMessage;
+ if (foundMessage) {
+ targetChannel = channel;
+ targetMessage = foundMessage;
- break;
- }
- } catch {
- continue;
+ break;
}
+ } catch {
+ continue;
}
}
+ }
- if (!foundMessage) {
- await message.reply("❌ Message not found.");
-
- return;
- }
- } catch {
- await message.reply("❌ Error finding message.");
+ if (!foundMessage) {
+ await message.reply("❌ Message not found.");
return;
}
- } else {
- const channelMatch = firstParameter.match(/<#(\d+)>/);
+ } catch {
+ await message.reply("❌ Error finding message.");
- if (!channelMatch) {
- await message.reply(
- "❌ Please mention a channel or provide a message ID. Example: `#general` or `1234567890123456789`",
- );
+ return;
+ }
+ } else {
+ const channelMatch = firstParameter.match(/<#(\d+)>/);
- return;
- }
+ if (!channelMatch) {
+ await message.reply(
+ "❌ Please mention a channel or provide a message ID. Example: `#general` or `1234567890123456789`",
+ );
- const channelId = channelMatch[1];
+ return;
+ }
- targetChannel = message.client.channels.cache.get(channelId);
+ const channelId = channelMatch[1];
- if (!targetChannel || !targetChannel.isTextBased()) {
- await message.reply("❌ Channel not found or is not a text channel.");
+ targetChannel = message.client.channels.cache.get(channelId);
- return;
- }
+ if (!targetChannel || !targetChannel.isTextBased()) {
+ await message.reply("❌ Channel not found or is not a text channel.");
+
+ return;
}
+ }
- try {
- await message.delete();
-
- const baseDuration = Math.max(1, messageContent.length / 20);
- const complexityMultiplier =
- (messageContent.match(/[.!?]/g) || []).length * 0.5;
- const wordCount = messageContent.split(" ").length;
- const wordComplexityMultiplier = Math.min(wordCount / 10, 2);
- const typingDuration = Math.min(
- baseDuration + complexityMultiplier + wordComplexityMultiplier,
- 8,
- );
+ try {
+ await message.delete();
+
+ const baseDuration = Math.max(1, messageContent.length / 20);
+ const complexityMultiplier =
+ (messageContent.match(/[.!?]/g) || []).length * 0.5;
+ const wordCount = messageContent.split(" ").length;
+ const wordComplexityMultiplier = Math.min(wordCount / 10, 2);
+ const typingDuration = Math.min(
+ baseDuration + complexityMultiplier + wordComplexityMultiplier,
+ 8,
+ );
+
+ await (targetChannel as any).sendTyping();
+ await new Promise((resolve) =>
+ setTimeout(resolve, typingDuration * 1000),
+ );
+
+ if (targetMessage) {
+ await targetMessage.reply(messageContent);
+ } else {
+ await (targetChannel as any).send(messageContent);
+ }
+ } catch (error) {
+ console.error("Error executing say command:", error);
- await (targetChannel as any).sendTyping();
- await new Promise((resolve) =>
- setTimeout(resolve, typingDuration * 1000),
+ try {
+ await message.reply(
+ "❌ Failed to execute the say command. Please check permissions.",
);
-
- if (targetMessage) {
- await targetMessage.reply(messageContent);
- } else {
- await (targetChannel as any).send(messageContent);
- }
- } catch (error) {
- console.error("Error executing say command:", error);
-
- try {
- await message.reply(
- "❌ Failed to execute the say command. Please check permissions.",
- );
- } catch (replyError) {
- console.error("Failed to send error reply:", replyError);
- }
+ } catch (replyError) {
+ console.error("Failed to send error reply:", replyError);
}
}
+ }
};