-
Notifications
You must be signed in to change notification settings - Fork 1
/
spotifyShareCommandsExtra.ts
181 lines (173 loc) · 6.38 KB
/
spotifyShareCommandsExtra.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2023 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, findOption, OptionalMessageOption } from "@api/Commands";
import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
import { FluxDispatcher } from "@webpack/common";
import { definePluginSettings } from "@api/Settings";
const settings = definePluginSettings({
AlbumText: {
description: "Album default prefix",
type: OptionType.STRING,
default: "",
restartNeeded: false,
},
AristText: {
description: "Artist default prefix",
type: OptionType.STRING,
default: "",
restartNeeded: false,
},
TrackText: {
description: "Track default prefix",
type: OptionType.STRING,
default: "",
restartNeeded: false,
}
});
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: "SpotifyShareCommandsExtra",
description: "Share your current Spotify track, album or artist via slash command (/track, /album, /artist) with a optinal prefix. modified version of spotifyShareCommands plugin! (MAKE SURE YOU HAVE SpotifyShareCommands DISABLED!)",
authors: [{
name: "AshAxolotl",
id: BigInt(461084048337403915n),
}],
dependencies: ["CommandsAPI"],
settings,
commands: [
{
name: "track",
description: "Send your current Spotify track to chat",
inputType: ApplicationCommandInputType.BUILT_IN,
options: [OptionalMessageOption],
execute: (opts, ctx) => {
const track: Track | null = Spotify.getTrack();
if (track === null) {
sendBotMessage(ctx.channel.id, {
content: "You're not listening to any music."
});
return;
}
if (findOption(opts, "message", "") == "") {
sendMessage(ctx.channel.id, {
content: settings.store.TrackText + " " + `https://open.spotify.com/track/${track.id}`
});
return;
}
// Note: Due to how Discord handles commands, we need to manually create and send the message
sendMessage(ctx.channel.id, {
content: findOption(opts, "message", "") + " " + `https://open.spotify.com/track/${track.id}`
});
}
},
{
name: "album",
description: "Send your current Spotify album to chat",
inputType: ApplicationCommandInputType.BUILT_IN,
options: [OptionalMessageOption],
execute: (opts, ctx) => {
const track: Track | null = Spotify.getTrack();
if (track === null) {
sendBotMessage(ctx.channel.id, {
content: "You're not listening to any music."
});
return;
}
if (findOption(opts, "message", "") == "") {
sendMessage(ctx.channel.id, {
content: settings.store.AlbumText + " " + `https://open.spotify.com/album/${track.album.id}`
});
return;
}
sendMessage(ctx.channel.id, {
content: findOption(opts, "message", "") + " " + `https://open.spotify.com/album/${track.album.id}`
});
}
},
{
name: "artist",
description: "Send your current Spotify artist to chat",
inputType: ApplicationCommandInputType.BUILT_IN,
options: [OptionalMessageOption],
execute: (opts, ctx) => {
const track: Track | null = Spotify.getTrack();
if (track === null) {
sendBotMessage(ctx.channel.id, {
content: "You're not listening to any music."
});
return;
}
if (findOption(opts, "message", "") == "") {
sendMessage(ctx.channel.id, {
content: settings.store.AristText + " " + track.artists[0].external_urls.spotify
});
return;
}
sendMessage(ctx.channel.id, {
content: findOption(opts, "message", "") + " " + track.artists[0].external_urls.spotify
});
}
}
]
});