2022-10-21 19:17:06 -04:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2022-10-19 18:53:09 -04:00
|
|
|
import { ApplicationCommandInputType, sendBotMessage } from "../api/Commands";
|
|
|
|
import { Devs } from "../utils/constants";
|
2022-11-07 17:34:14 -05:00
|
|
|
import { lazyWebpack } from "../utils/misc";
|
2022-10-22 12:18:41 -04:00
|
|
|
import definePlugin from "../utils/types";
|
|
|
|
import { filters } from "../webpack";
|
2022-10-19 18:53:09 -04:00
|
|
|
import { FluxDispatcher } from "../webpack/common";
|
|
|
|
|
|
|
|
interface Album {
|
2022-10-23 17:23:52 -04:00
|
|
|
id: string;
|
2022-10-19 18:53:09 -04:00
|
|
|
image: {
|
2022-10-23 17:23:52 -04:00
|
|
|
height: number;
|
|
|
|
width: number;
|
|
|
|
url: string;
|
|
|
|
};
|
|
|
|
name: string;
|
2022-10-19 18:53:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Artist {
|
|
|
|
external_urls: {
|
2022-10-23 17:23:52 -04:00
|
|
|
spotify: string;
|
|
|
|
};
|
|
|
|
href: string;
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
type: "artist" | string;
|
|
|
|
uri: string;
|
2022-10-19 18:53:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
interface Track {
|
2022-10-23 17:23:52 -04:00
|
|
|
id: string;
|
|
|
|
album: Album;
|
|
|
|
artists: Artist[];
|
|
|
|
duration: number;
|
|
|
|
isLocal: boolean;
|
|
|
|
name: string;
|
2022-10-19 18:53:09 -04:00
|
|
|
}
|
|
|
|
|
2022-10-30 15:45:18 -04:00
|
|
|
const Spotify = lazyWebpack(filters.byProps("getPlayerState"));
|
|
|
|
const MessageCreator = lazyWebpack(filters.byProps("getSendMessageOptionsForReply", "sendMessage"));
|
|
|
|
const PendingReplyStore = lazyWebpack(filters.byProps("getPendingReply"));
|
2022-10-19 18:53:09 -04:00
|
|
|
|
|
|
|
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: "Sendify",
|
|
|
|
description: "Send your current Spotify music to chat",
|
|
|
|
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
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|