/[sudobot]/branches/4.x/src/commands/information/SpotifyCommand.ts
ViewVC logotype

Contents of /branches/4.x/src/commands/information/SpotifyCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months, 1 week ago) by rakinar2
File MIME type: application/typescript
File size: 4046 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 /**
2 * This file is part of SudoBot.
3 *
4 * Copyright (C) 2021-2022 OSN Inc.
5 *
6 * SudoBot is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * SudoBot is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 import { formatDistanceToNowStrict } from "date-fns";
21 import { CommandInteraction, GuildMember, Message, MessageActionRow, MessageButton } from "discord.js";
22 import DiscordClient from "../../client/Client";
23 import MessageEmbed from "../../client/MessageEmbed";
24 import CommandOptions from "../../types/CommandOptions";
25 import InteractionOptions from "../../types/InteractionOptions";
26 import getUser from "../../utils/getUser";
27 import BaseCommand from "../../utils/structures/BaseCommand";
28
29 export default class SpotifyCommand extends BaseCommand {
30 name = "spotify";
31 category = "information";
32 aliases = ["music"];
33 supportsInteractions = true;
34
35 async run(client: DiscordClient, message: CommandInteraction | Message, options: CommandOptions | InteractionOptions) {
36 const member = <GuildMember> (options.isInteraction ? options.options.getMember('member') ?? message.member! : (
37 options.args[0] ? await getUser(client, message as Message, options, 0) : message.member!
38 ));
39
40 const listeningActivity = member.presence?.activities.find(a => a.type === 'LISTENING' && a.name === 'Spotify');
41
42 if (!listeningActivity) {
43 await message.reply(`${member.id === message.member!.user.id ? 'You are' : 'The user is'} not listening to Spotify.`);
44 return;
45 }
46
47 const url = listeningActivity.syncId ? `https://open.spotify.com/track/${listeningActivity.syncId}` : null;
48 `:notes: Listening to **Spotify**: ${url ? '[' : '**'}${listeningActivity.state?.replace(/\;/, ',')} - ${listeningActivity.details}${url ? '](' + url + ')' : '**'}`;
49
50 console.log(listeningActivity.assets?.smallImageURL());
51
52 await message.reply({
53 embeds: [
54 new MessageEmbed({
55 author: {
56 name: member.user.tag,
57 iconURL: member.user.displayAvatarURL()
58 },
59 thumbnail: {
60 url: listeningActivity.assets?.smallImageURL() ?? listeningActivity.assets?.largeImageURL() ?? undefined
61 },
62 description: `:notes: **${member.user.toString()}** is listening ${url ? '[' : '**'}${listeningActivity.state?.replace(/\;/, ',')} - ${listeningActivity.details}${url ? '](' + url + ')' : '**'}`,
63 fields: [
64 {
65 name: 'Activity Start Date',
66 value: `${listeningActivity.createdAt.toUTCString()} (${formatDistanceToNowStrict(listeningActivity.createdAt, { addSuffix: true })})`
67 }
68 ],
69 footer: {
70 text: 'Listening to Spotify',
71 iconURL: 'https://media.discordapp.net/attachments/969258443754074143/1056571821350203513/991px-Spotify_icon.png'
72 }
73 })
74 ],
75 components: url ? [
76 new MessageActionRow<MessageButton>()
77 .addComponents(
78 new MessageButton()
79 .setStyle("LINK")
80 .setURL(url!)
81 .setLabel("Listen Along")
82 )
83 ] : undefined
84 });
85 }
86 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26