-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
168 lines (159 loc) Β· 3.62 KB
/
utils.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import "dotenv/config"
import fetch from "node-fetch"
import { verifyKey } from "discord-interactions"
export function verifydiscordRequest(clientKey) {
return function (req, res, buf, encoding) {
const signature = req.get("X-Signature-Ed25519")
const timestamp = req.get("X-Signature-Timestamp")
const isValidRequest = verifyKey(buf, signature, timestamp, clientKey)
if (!isValidRequest) {
res.status(401).send("Bad request signature")
throw new Error("Bad request signature")
}
}
}
export async function discordRequest(endpoint, options) {
// append endpoint to root API URL
const url = "https://discord.com/api/v9/" + endpoint
// Stringify payloads
if (options.body) options.body = JSON.stringify(options.body)
// Use node-fetch to make requests
const res = await fetch(url, {
headers: {
Authorization: `Bot ${process.env.DISCORD_TOKEN}`,
"Content-Type": "application/json; charset=UTF-8",
},
...options,
})
// throw API errors
if (!res.ok) {
const data = await res.json()
console.log(res.status)
throw new Error(JSON.stringify(data))
}
// return original response
return res
}
// Simple method that returns a random emoji from list
export function getRandomEmoji() {
const emojiList = [
"π",
"π",
"π",
"π€",
"π",
"π€",
"π€",
"πΆβπ«οΈ",
"π",
"πΈ",
"πΏ",
"π",
"π",
"β¨",
]
return emojiList[Math.floor(Math.random() * emojiList.length)]
}
export function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}
export function memberAdmin(member) {
let roles = member.roles
if (roles) {
if (member.roles.indexOf("965040006353805312") != -1) {
console.log(`${member.user.username} is an admin`)
return true
} else {
return false
}
} else {
return false
}
}
export function logStatement(member, command) {
console.log(`${member.user.username} ran ${command}`)
}
export function notAdminMsg(res, InteractionResponseType) {
return res.send({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
// Fetches a random emoji to send from a helper function
content: "You must be an admin to run that command",
flags: 1 << 6, //ephemeral msg flag
},
})
}
export const testQueue = [
{
user_id: "807313410009202788",
user_name: "Ramirezd12",
queued: true,
games_played: 0,
},
{
user_id: "498945479397343253",
user_name: "FadedKoalaZ",
queued: true,
games_played: 0,
},
{
user_id: "882498923476955147",
user_name: "Prasler",
queued: true,
games_played: 0,
},
{
user_id: "698444987964194876",
user_name: "semkki",
queued: true,
games_played: 0,
},
{
user_id: "877560701999276032",
user_name: "KJRawks",
queued: true,
games_played: 0,
},
{
user_id: "303845825476558859",
user_name: "dougtck",
queued: true,
games_played: 0,
},
{
user_id: "406592785982947330",
user_name: "EVIL",
queued: true,
games_played: 0,
},
{
user_id: "721516076629885111",
user_name: "TheChef",
queued: true,
games_played: 0,
},
{
user_id: "482648605195501578",
user_name: "Ghost773",
queued: true,
games_played: 0,
},
{
user_id: "956704701112528927",
user_name: "kippotoe",
queued: true,
games_played: 0,
},
{
user_id: "429132478268047376",
user_name: "MuΓ±e",
queued: true,
games_played: 0,
},
{
user_id: "439987718060113941",
user_name: "Profantasies",
queued: true,
games_played: 0,
},
]