aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/spotifyShareCommands/index.ts
diff options
context:
space:
mode:
authorV <vendicated@riseup.net>2023-09-24 16:02:18 +0200
committerV <vendicated@riseup.net>2023-09-24 16:02:18 +0200
commit30ac25607023752031aa98060cbf8a736109992d (patch)
tree79bb82b6634ef601db6c98e751275607ec54dbea /src/plugins/spotifyShareCommands/index.ts
parentd0e2a324717e600736a18b88fe89a21c640a406b (diff)
downloadVencord-30ac25607023752031aa98060cbf8a736109992d.tar.gz
Vencord-30ac25607023752031aa98060cbf8a736109992d.tar.bz2
Vencord-30ac25607023752031aa98060cbf8a736109992d.zip
migrate all plugins to folders
Diffstat (limited to 'src/plugins/spotifyShareCommands/index.ts')
-rw-r--r--src/plugins/spotifyShareCommands/index.ts138
1 files changed, 138 insertions, 0 deletions
diff --git a/src/plugins/spotifyShareCommands/index.ts b/src/plugins/spotifyShareCommands/index.ts
new file mode 100644
index 0000000..7634e9d
--- /dev/null
+++ b/src/plugins/spotifyShareCommands/index.ts
@@ -0,0 +1,138 @@
+/*
+ * Vencord, a modification for Discord's desktop app
+ * Copyright (c) 2022 Vendicated and contributors
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+import { ApplicationCommandInputType, sendBotMessage } from "@api/Commands";
+import { Devs } from "@utils/constants";
+import definePlugin from "@utils/types";
+import { findByPropsLazy } from "@webpack";
+import { FluxDispatcher } from "@webpack/common";
+
+interface Album {
+ id: string;
+ image: {
+ height: number;
+ width: number;
+ url: string;
+ };
+ name: string;
+}
+
+interface Artist {
+ external_urls: {
+ spotify: string;
+ };
+ href: string;
+ id: string;
+ name: string;
+ type: "artist" | string;
+ uri: string;
+}
+
+interface Track {
+ id: string;
+ album: Album;
+ artists: Artist[];
+ duration: number;
+ isLocal: boolean;
+ name: string;
+}
+
+const Spotify = findByPropsLazy("getPlayerState");
+const MessageCreator = findByPropsLazy("getSendMessageOptionsForReply", "sendMessage");
+const PendingReplyStore = findByPropsLazy("getPendingReply");
+
+function sendMessage(channelId, message) {
+ message = {
+ // The following are required to prevent Discord from throwing an error
+ invalidEmojis: [],
+ tts: false,
+ validNonShortcutEmojis: [],
+ ...message
+ };
+ const reply = PendingReplyStore.getPendingReply(channelId);
+ MessageCreator.sendMessage(channelId, message, void 0, MessageCreator.getSendMessageOptionsForReply(reply))
+ .then(() => {
+ if (reply) {
+ FluxDispatcher.dispatch({ type: "DELETE_PENDING_REPLY", channelId });
+ }
+ });
+}
+
+export default definePlugin({
+ name: "SpotifyShareCommands",
+ description: "Share your current Spotify track, album or artist via slash command (/track, /album, /artist)",
+ authors: [Devs.katlyn],
+ dependencies: ["CommandsAPI"],
+ commands: [
+ {
+ name: "track",
+ description: "Send your current Spotify track to chat",
+ inputType: ApplicationCommandInputType.BUILT_IN,
+ options: [],
+ execute: (_, ctx) => {
+ const track: Track | null = Spotify.getTrack();
+ if (track === null) {
+ sendBotMessage(ctx.channel.id, {
+ content: "You're not listening to any music."
+ });
+ return;
+ }
+ // Note: Due to how Discord handles commands, we need to manually create and send the message
+ sendMessage(ctx.channel.id, {
+ content: `https://open.spotify.com/track/${track.id}`
+ });
+ }
+ },
+ {
+ name: "album",
+ description: "Send your current Spotify album to chat",
+ inputType: ApplicationCommandInputType.BUILT_IN,
+ options: [],
+ execute: (_, ctx) => {
+ const track: Track | null = Spotify.getTrack();
+ if (track === null) {
+ sendBotMessage(ctx.channel.id, {
+ content: "You're not listening to any music."
+ });
+ return;
+ }
+ sendMessage(ctx.channel.id, {
+ content: `https://open.spotify.com/album/${track.album.id}`
+ });
+ }
+ },
+ {
+ name: "artist",
+ description: "Send your current Spotify artist to chat",
+ inputType: ApplicationCommandInputType.BUILT_IN,
+ options: [],
+ execute: (_, ctx) => {
+ const track: Track | null = Spotify.getTrack();
+ if (track === null) {
+ sendBotMessage(ctx.channel.id, {
+ content: "You're not listening to any music."
+ });
+ return;
+ }
+ sendMessage(ctx.channel.id, {
+ content: track.artists[0].external_urls.spotify
+ });
+ }
+ }
+ ]
+});