-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
88 lines (68 loc) · 2.74 KB
/
index.js
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
import { Client, Intents, MessageEmbed } from 'discord.js';
import fetch from 'node-fetch';
import * as dotenv from "dotenv";
dotenv.config();
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = "!"
client.once("ready", () => {
console.log("Bot logged in and ready")
})
client.on("messageCreate", async (message) => {
let idArg = "";
let collectionArg = "";
if (!message.content.startsWith(prefix) || message.author.bot || message.channelId !== "900824546125430844") {
return;
} else {
const args = message.content.slice(prefix.length).split(" ");
const command = args.shift().toLowerCase()
if (args.indexOf("id") === -1) {
return;
}
if (command === "rarity") {
idArg = args.pop();
args.pop()
while (args.length > 0) {
collectionArg += args.shift() + " "
}
console.log(idArg)
console.log(collectionArg)
if (idArg && collectionArg) {
const res = await fetch(`https://rarity-radar.vercel.app/api/collections/${collectionArg.trim()}/tokens/${idArg.trim()}`)
if (res.status === 200) {
const resData = await res.json()
const exampleEmbed = {
color: 0x0099ff,
title: resData.name || collectionArg.trim() + " " + resData.rank.toString(),
fields: [
{
name: 'Rank',
value: resData.rank.toString(),
inline: true,
},
{
name: 'Rarity Score',
value: resData.rarityScore.toFixed(2).toString(),
inline: true,
},
{
name: 'Mean Percentage',
value: resData.meanPercentage.toFixed(2).toString() + "%",
inline: true,
},
],
image: {
url: resData.image,
},
timestamp: new Date(),
};
message.channel.send({ embeds: [exampleEmbed] });
} else {
message.channel.send("No collection or tokenId matching " + collectionArg.trim() + " " + idArg.trim())
}
} else {
return
}
}
}
})
client.login(process.env.BOT_TOKEN)