-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
366 lines (351 loc) · 10.1 KB
/
mod.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
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
import {
ApplicationCommandInteraction,
Client,
Embed,
event,
GatewayIntents,
Interaction,
InteractionUser,
isMessageComponentInteraction,
MessageComponentType,
slash,
MessageComponentData,
} from "harmony";
import { commands } from "./objects/cmds.ts";
import { sentBy } from "./lib/embed.ts";
import {
timeToUTCMidnight,
cardArrayToWords,
cardsToWords,
} from "./lib/misc.ts";
import { findUser, doDaily, changeBal, BalanceMutationType } from "./lib/db.ts";
import "https://deno.land/std@0.190.0/dotenv/load.ts";
class EcoBot extends Client {
@event()
async ready() {
await console.log("Ready! Running bot as", bot.user!.tag);
this.interactions.commands
.bulkEdit(commands, "916006382594064385")
.then(() => console.log("Commands created!"));
}
@event()
async interactionCreate(d: Interaction) {
if (!isMessageComponentInteraction(d)) return;
//if (d.guild == undefined || d.channel == undefined) return;
//if (d.message.author.id != this.client.user!.id) return;
await d.reply({
embeds: [
new Embed({
title:
"Opening " +
cardsToWords(parseInt(d.customID.toLowerCase())) +
"...",
}),
new Embed({
image: {
url: "https://tenor.com/view/whats-in-the-box-box-wondering-unpack-open-gif-16055318",
},
}).setAuthor("Give it a second!"),
],
});
setTimeout(() => {
d.editResponse({
embeds: [
new Embed({
title: "Opened Card!",
}),
new Embed({
title: "Here's what you got:",
description: "100000P\n One Raffle Entry",
}),
],
});
}, 2000);
}
@slash()
async ping(d: ApplicationCommandInteraction): Promise<void> {
const desc: string = d.option<string>("channel") || "";
await d.reply({
//ephemeral: true,
embeds: [
new Embed({
title: "Pong 🏓",
description:
"Sent to " +
desc +
" (not actually cause I figured this would be abused)",
}).setColor("RED"),
],
});
}
@slash()
async balance(d: ApplicationCommandInteraction): Promise<void> {
const user = d.option<InteractionUser>("user") || undefined; //User from second part of the cmd
const balance =
user != undefined
? (await findUser(user.id)).bal
: (await findUser(d.user.id)).bal;
await d.reply({
//ephemeral: true,
embeds: [
new Embed({
title: "Balance 💰",
description:
(user == undefined ? "You have " : user.mention + " has ") + "$" +
balance +
".",
}).setColor("#E7D27C"),
],
});
}
@slash()
async profile(d: ApplicationCommandInteraction): Promise<void> {
const target = d.option<InteractionUser>("user") || undefined;
const profile =
target == undefined
? await findUser(d.user.id)
: await findUser(target.id);
await d.reply({
embeds: [
new Embed({
title: `${
target == undefined ? "Your" : target.username + "'s"
} Profile`,
fields: [
{
name: "Balance",
value: profile.bal.toString(),
},
{
name: "Deck",
value:
profile.cards.join(", ") == ""
? "Your deck is empty"
: cardArrayToWords(profile.cards).join(", "),
},
{
name: "Inventory",
value:
profile.inventory.join(", ") == ""
? "Your inventory is empty"
: profile.inventory.join(", "),
},
],
}).setColor("#E7D27C"),
],
});
}
@slash()
async daily(d: ApplicationCommandInteraction): Promise<void> {
const daily = await doDaily(d.member!.id, (await d.member?.roles.resolve("916045092840681592") )!= undefined);
if (daily.failed == true) {
const midnight = new Date(Date.now()).setUTCHours(24, 0, 0, 0) - Date.now();
const time = (midnight / 1000)
.toFixed(
0,
);
await d.reply({
//ephemeral: true,
embeds: [
new Embed({
title: "You can't do this yet!",
description:
"To keep our economy fair for everyone, we allow people to add to their streaks at midnight UTC.",
fields: [
{
inline: true,
name: "Time until next claim:",
value: `<t:${time}:R>`,
},
],
...sentBy(d),
}).setColor("#FF6961"),
],
});
} else {
await d.reply({
//ephemeral: true,
embeds: [
new Embed({
title: "Daily Reward Recived!",
fields: [
{
name: "Balance",
value: daily.balance!.toString(),
},
daily.rewards && daily.rewards.length != 0
? {
name: "Other",
value: cardArrayToWords(daily.rewards).join(", "),
}
: {
name: "Other",
value:
"No other rewards 😭. Active rank gets extra rewards! Learn about active rank in <#916045092840681592>.",
},
],
}).setColor("#77DD77"),
],
});
}
}
@slash()
async open(d: ApplicationCommandInteraction): Promise<void> {
const profile = await findUser(d.user.id);
if (profile.cards.length == 0) {
await d.reply({
embeds: [
new Embed({
title: "Your deck is empty 😭",
description: "You can obtain cards via `/daily`.",
}),
],
});
return;
}
const crds: MessageComponentData[] = [];
profile.cards.forEach((v) => {
const name = cardsToWords(v);
const output: MessageComponentData = {
label: name,
style:
v == 0 || v == 5
? 2
: v == 1 || v == 6
? 1
: v == 2 || v == 7
? 3
: v == 3 || v == 8
? 4
: v == 4 || v == 9
? 1
: 2,
type: MessageComponentType.BUTTON,
customID: v.toString(),
};
crds.push(output);
});
await d.reply({
embeds: [
new Embed({
title: "Open Cards",
description: "Select a card from the menu below to open it",
}),
],
components: [
{
type: MessageComponentType.ACTION_ROW,
components: [...crds],
},
],
});
}
@slash()
async admin(d: ApplicationCommandInteraction): Promise<void> {
const user = d.option<InteractionUser>("user");
const amount = d.option<number>("amount");
if (d.member && d.member.permissions.has("MANAGE_GUILD", true)) {
switch (d.subCommand) {
case "setbal":
if (amount < 1000000000) {
await changeBal(user.id, amount, BalanceMutationType.ADD);
await d.reply({
//ephemeral: true,
embeds: [
new Embed({
title: "Balance Updated",
description:
"Set " + user.mention + "'s balance to $" + amount + ".",
...sentBy(d),
}).setColor("#77DD77"),
],
});
} else {
await d.reply({
ephemeral: true,
embeds: [
new Embed({
title: "Error",
description: "An unknown error occurred (too much money?)",
}).setColor("#FF6961"),
],
});
}
break;
case "addbal":
if (
d.member &&
amount < 1000000000
) {
await changeBal(user.id, amount, BalanceMutationType.ADD);
await d.reply({
//ephemeral: true,
embeds: [
new Embed({
title: "Balance Updated",
description:
"Added $" + amount + " to " + user.mention + "'s balance.",
}).setColor("#77DD77"),
],
});
} else {
await d.reply({
ephemeral: true,
embeds: [
new Embed({
title: "Error",
description: "An unknown error occurred (too much money?)",
}).setColor("#FF6961"),
],
});
}
break;
case "subtractbal":
if (
d.member &&
amount < 1000000000
) {
await changeBal(user.id, amount, BalanceMutationType.SUBTRACT);
await d.reply({
//ephemeral: true,
embeds: [
new Embed({
title: "Balance Updated",
description:
"Set " + user.mention + "'s balance to $" + amount + ".",
}).setColor("#77DD77"),
],
});
} else {
await d.reply({
ephemeral: true,
embeds: [
new Embed({
title: "Error",
description: "An unknown error occurred (too much money?)",
}).setColor("#FF6961"),
],
});
}
}
} else {
await d.reply({
ephemeral: true,
embeds: [
new Embed({
title: "Error",
description: "You need the manage server permission to do this.",
}).setColor("#FF6961"),
],
});
}
}
}
const bot = new EcoBot({ clientProperties: {browser: "Discord iOS"}});
/*bot.on('ready', () => {
console.log('Ready!')
})*/
bot.interactions.on("interactionError", console.error);
bot.setPresence({ type: "CUSTOM_STATUS", name: "Listening to /help (jk)" });
// Proceed with connecting to Discord (login)
bot.connect(Deno.env.get("TOKEN"), [GatewayIntents.GUILD_MEMBERS]);