-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmyhatredtowardsspotifyisinfinite.ts
88 lines (70 loc) · 2.66 KB
/
myhatredtowardsspotifyisinfinite.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
/*
* Vencord, a modification for Discord's desktop app
* Copyright (c) 2022 exhq
*
* 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 { sendBotMessage } from "@api/Commands";
import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { FluxDispatcher, SelectedChannelStore } from "@webpack/common";
import { Message } from "discord-types/general";
interface IMessageCreate {
type: "MESSAGE_CREATE";
optimistic: boolean;
isPushNotification: boolean;
channelId: string;
message: Message;
}
async function youtuberify(link: string): Promise<string | undefined> {
if (link.includes("playlist")) {
return;
}
return await fetch(`https://youtuber.exhq.workers.dev/${link}`).then(it => it.text());
}
const getSubString = (s: string) => {
const regex = /https:\/\/open.spotify.com\/track\/[a-zA-Z0-9]+/g;
const matches = regex.exec(s);
if (matches !== null) {
return matches[0];
} else {
return "";
}
};
export default definePlugin({
name: "fuck spotify",
authors: [Devs.echo],
description: "returns the corresponding youtube link of a spotify link",
async onMessage(e: IMessageCreate) {
if (e.optimistic || e.type !== "MESSAGE_CREATE") return;
if (e.message.state === "SENDING") return;
if (e.message.author?.bot) return;
if (!e.message.content) return;
if (e.channelId !== SelectedChannelStore.getChannelId()) return;
if (e.message.content.toLowerCase().includes("open.spotify.com") && !e.message.content.toLowerCase().includes("playlist")) {
const x = getSubString(e.message.content);
const funny = await youtuberify(x);
if (funny?.includes("https://<!DOCTYPE html><html lang=\"en\"")) {
return;
}
sendBotMessage(e.message.channel_id, { content: funny });
}
},
start() {
FluxDispatcher.subscribe("MESSAGE_CREATE", this.onMessage);
},
stop() {
FluxDispatcher.unsubscribe("MESSAGE_CREATE", this.onMessage);
},
});