From 14f44458f9778d8894b963df519e8b65b2dcc2cf Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Fri, 11 Feb 2022 12:14:49 -0500 Subject: [PATCH] feat(plugins/helpers): add `sendTextMessage` to send a simple string (#2033) * feat: sendTextMessage to send simple string * fix: clean up imports * Update plugins/helpers/mod.ts Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com> Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com> --- plugins/helpers/mod.ts | 8 ++++++++ plugins/helpers/src/sendTextMessage.ts | 11 +++++++++++ 2 files changed, 19 insertions(+) create mode 100644 plugins/helpers/src/sendTextMessage.ts diff --git a/plugins/helpers/mod.ts b/plugins/helpers/mod.ts index e492c31ce..3691ffb35 100644 --- a/plugins/helpers/mod.ts +++ b/plugins/helpers/mod.ts @@ -25,6 +25,10 @@ export interface BotWithHelpersPlugin extends Bot { userId: bigint, content: string | CreateMessage, ) => Promise; + sendTextMessage: ( + channelId: bigint, + content: string | CreateMessage, + ) => Promise; suppressEmbeds: ( channelId: bigint, messageId: bigint, @@ -70,6 +74,10 @@ export function enableHelpersPlugin(rawBot: Bot): BotWithHelpersPlugin { userId: bigint, content: string | CreateMessage, ) => sendDirectMessage(bot, userId, content); + bot.helpers.sendTextMessage = ( + channelId: bigint, + content: string | CreateMessage, + ) => sendTextMessage(bot, channelId, content); bot.helpers.suppressEmbeds = (channelId: bigint, messageId: bigint) => suppressEmbeds(bot, channelId, messageId); bot.helpers.archiveThread = (threadId: bigint) => archiveThread(bot, threadId); bot.helpers.unarchiveThread = (threadId: bigint) => unarchiveThread(bot, threadId); diff --git a/plugins/helpers/src/sendTextMessage.ts b/plugins/helpers/src/sendTextMessage.ts new file mode 100644 index 000000000..76162e210 --- /dev/null +++ b/plugins/helpers/src/sendTextMessage.ts @@ -0,0 +1,11 @@ +import { Bot, CreateMessage } from "../deps.ts"; + +/** Sends a text message. */ +export async function sendTextMessage( + bot: Bot, + channelId: bigint, + content: string | CreateMessage, +) { + if (typeof content === "string") content = { content }; + return bot.helpers.sendMessage(channelId, content); +}