From bdede5c525a57e4f5fe8f5cfff0236a157bfabdc Mon Sep 17 00:00:00 2001 From: Christian Toney Date: Mon, 23 Dec 2024 10:33:00 -0500 Subject: [PATCH] Add feature: Muting --- src/commands/mute.ts | 23 +++++++++++++++++++++++ src/commands/unfollow.ts | 4 ++-- src/utils/interact-with-bluesky-now.ts | 5 +++-- src/utils/interact-with-bluesky.ts | 6 +++--- 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 src/commands/mute.ts diff --git a/src/commands/mute.ts b/src/commands/mute.ts new file mode 100644 index 0000000..5087c61 --- /dev/null +++ b/src/commands/mute.ts @@ -0,0 +1,23 @@ +import Command from "#utils/Command.js" +import { ApplicationCommandOptionTypes } from "oceanic.js"; +import interactWithBlueskyNow from "#utils/interact-with-bluesky-now.js"; + +const muteNowCommand = new Command({ + name: "mute", + description: "Mute an account on Bluesky.", + options: [ + { + type: ApplicationCommandOptionTypes.STRING, + name: "handle", + description: "What's the name of the account?", + required: true + } + ], + async action(interaction) { + + return await interactWithBlueskyNow(interaction, "mute", "mute"); + + } +}); + +export default muteNowCommand; \ No newline at end of file diff --git a/src/commands/unfollow.ts b/src/commands/unfollow.ts index f456312..505665c 100644 --- a/src/commands/unfollow.ts +++ b/src/commands/unfollow.ts @@ -2,7 +2,7 @@ import Command from "#utils/Command.js" import { ApplicationCommandOptionTypes } from "oceanic.js"; import interactWithBlueskyNow from "#utils/interact-with-bluesky-now.js"; -const unlikeNowCommand = new Command({ +const unfollowNowCommand = new Command({ name: "unfollow", description: "Unfollow an account on Bluesky.", options: [ @@ -20,4 +20,4 @@ const unlikeNowCommand = new Command({ } }); -export default unlikeNowCommand; \ No newline at end of file +export default unfollowNowCommand; \ No newline at end of file diff --git a/src/utils/interact-with-bluesky-now.ts b/src/utils/interact-with-bluesky-now.ts index 48f45cc..dc9405c 100644 --- a/src/utils/interact-with-bluesky-now.ts +++ b/src/utils/interact-with-bluesky-now.ts @@ -11,7 +11,7 @@ import { authenticator } from "otplib"; import IncorrectDecryptionKeyError from "./errors/IncorrectDecryptionKeyError.js"; import MFAIncorrectCodeError from "./errors/MFAIncorrectCodeError.js"; -async function interactWithBlueskyNow(interaction: CommandInteraction | ComponentInteraction | ModalSubmitInteraction, customIDPrefix: string, action: "deleteFollow" | "follow" | "deleteRepost" | "like" | "deleteLike" | "repost") { +async function interactWithBlueskyNow(interaction: CommandInteraction | ComponentInteraction | ModalSubmitInteraction, customIDPrefix: string, action: "mute" | "deleteFollow" | "follow" | "deleteRepost" | "like" | "deleteLike" | "repost") { const guildID = getGuildIDFromInteraction(interaction); @@ -27,7 +27,8 @@ async function interactWithBlueskyNow(interaction: CommandInteraction | Componen deleteLike: "💔", deleteRepost: "🗑️", follow: "➕", - deleteFollow: "➖" + deleteFollow: "➖", + mute: "🔕" }; await interaction.editOriginal({ content: responses[action], diff --git a/src/utils/interact-with-bluesky.ts b/src/utils/interact-with-bluesky.ts index a4b7d64..c80cc4e 100644 --- a/src/utils/interact-with-bluesky.ts +++ b/src/utils/interact-with-bluesky.ts @@ -3,11 +3,11 @@ import blueskyClient from "./bluesky-client.js"; import { Agent } from "@atproto/api"; import { isThreadViewPost } from "@atproto/api/dist/client/types/app/bsky/feed/defs.js"; -async function interactWithBluesky(source: {interaction?: ModalSubmitInteraction | ComponentInteraction, rkey?: string, targetHandle?: string, actorDID?: string, guildID: string, decryptionKey?: string}, action: "deleteFollow" | "follow" | "deletePost" | "deleteLike" | "like" | "deleteRepost" | "repost") { +async function interactWithBluesky(source: {interaction?: ModalSubmitInteraction | ComponentInteraction, rkey?: string, targetHandle?: string, actorDID?: string, guildID: string, decryptionKey?: string}, action: "mute" | "deleteFollow" | "follow" | "deletePost" | "deleteLike" | "like" | "deleteRepost" | "repost") { let {interaction, rkey, targetHandle, actorDID} = source; - const isTargetAccount = action === "deleteFollow" || action === "follow"; + const isTargetAccount = action === "deleteFollow" || action === "follow" || action === "mute"; if (interaction && !targetHandle) { // Get the rkey of the post. @@ -46,7 +46,7 @@ async function interactWithBluesky(source: {interaction?: ModalSubmitInteraction uri = profileResponse.data.viewer?.following; if (!uri) return; - } else if (action !== "follow") { + } else if (!isTargetAccount) { if (!rkey) throw new Error();