-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.ts
110 lines (94 loc) · 3.05 KB
/
index.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
import { Message, Intents, MessageEmbed, Client } from "discord.js";
import { FinalTorrent } from "./modules/types";
import * as fs from "fs";
import { grabTorrents } from "./modules/torrent";
const client: Client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
let token: string; //empty login token, initially.
//Command Prefix
const prefix = ".";
//setting token
if (fs.existsSync("./config.json")) {
token = JSON.parse(fs.readFileSync("./config.json").toString()).token;
} else {
token = process.argv[2].toString();
}
//Start-up event
client.on("ready", () => {
client.user.setPresence({
activities: [
{
name: `.help | .invite | .github | ${client.guilds.cache.size} servers`,
},
],
status: "online",
});
console.log(`Bot is up and running in ${client.guilds.cache.size} servers!`);
});
// Message in chat event
client.on("messageCreate", async (msg: Message) => {
if (!msg.content.startsWith(prefix) || msg.author.bot) {
return;
}
const args: string[] = msg.content.slice(prefix.length).trim().split(/ +/);
const command: string = args.shift().toLowerCase();
let query = "";
args.map((string) => {
query += " " + string;
});
switch (command) {
case "torrent":
msg.channel.sendTyping();
const torrentArray: FinalTorrent[] = await grabTorrents(query);
if (torrentArray.length > 0) {
let torrentList: MessageEmbed = new MessageEmbed();
torrentList.setAuthor(`@${msg.author.username}`);
torrentArray.map((torrent: FinalTorrent) => {
torrentList.addFields({
name: `${torrent.number}. ${torrent.title}`,
value: `${torrent.magnet} | Seeders: ${torrent.seeds} | Size: ${torrent.size}`,
});
});
msg.channel.send({ embeds: [torrentList] }); //Send them the list of torrents in the channel
} else {
msg.channel.send({
embeds: [
new MessageEmbed()
.setTitle("No results were returned.")
.setAuthor(msg.author.username)
.addFields([
{
name: "Not found",
value:
"Torrent not found on 1337x, please refine your search.",
},
])
],
});
}
break;
case "github":
msg.channel.send({
embeds: [
new MessageEmbed()
.setTitle("Bot's GitHub")
.setAuthor("Cryptoguys")
.setURL("https://github.com/brandongallagher1999/1337x-Bot")
.addFields({
name: "Help out!",
value: "Go give the repo a star! :star:",
}),
],
});
break;
case "help":
msg.channel.send(
"``` .torrent <torrent name> // .torrent The Witcher 3 Wild Hunt \n .invite // Invite link to the Discord Bot```"
);
break;
}
});
grabTorrents("Get rid of cloudflare error pls"); //initial query allows us to query from the bot without cloudflare exception
client.login(token);
export {};