-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.js
More file actions
575 lines (473 loc) · 22.1 KB
/
util.js
File metadata and controls
575 lines (473 loc) · 22.1 KB
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
// All helper functions for index.js
const express = require('express')
const app = express()
const fs = require('fs')
var cron = require('node-cron')
require("dotenv").config()
const { OpenAI } = require("openai");
const openai = new OpenAI({
apiKey: process.env.OPEN_AI_TOKEN,
});
const discord = require('discord.js')
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
]
});
var saveData;
global.saveData = load();
function cmd(msg, command_string){
return msg.content.toLowerCase().includes("!" + command_string);
}
async function askAI(prompt, author_id){
const response = await openai.chat.completions.create({
messages: [{role: "system", content: "You are an announcer in an online Pokemon-like game where several users attempt to \"catch\" various Pokemon and obtain points based on the rarity value of the Pokemon they catch, as well as add those Pokemon to their \"Pokedex\". Keep all following answers to a very short, concise paragraph. You personality should be: " + saveData[author_id]["AIPersonality"] + ". Make sure to answer all following prompts heavily flavored with your personality"},
{ role: "user", content: prompt }],
model: "gpt-3.5-turbo",
});
return response.choices[0].message.content;
}
async function adjustPoints(saveData, msg, user, amount, pointSign, pointPrefix) {
if (!(msg.member.roles.cache.some(role => role.name === 'PokemonBotManager') || "" + msg.author.id === process.env.AUTHOR_ID)) {
return "You are not a PokémonBotManager :eyes:";
}
if (checkOffLimits(msg)) {
return;
}
if (!user || checkOffLimits(msg)) {
return "No user mentioned, please specify a person.";
}
if (isNaN(amount) || amount <= 0) {
return "Please specify a valid number of points.";
}
if (saveData[user.id] === undefined) {
setupDefaultsIfNecessary(saveData, user.id, user.globalName);
}
if (pointSign == "+") {
saveData[user.id][pointPrefix + "points"] = saveData[user.id][pointPrefix + "points"] + amount;
save(saveData);
return `Added ${amount} points to ${user.globalName}'s "${pointPrefix}points" for a total of ${saveData[user.id][pointPrefix + "points"]}.`;
} else {
saveData[user.id][pointPrefix + "points"] = saveData[user.id][pointPrefix + "points"] - amount;
save(saveData);
return `Subtracted ${amount} points from ${user.globalName}'s "${pointPrefix}points" for a total of ${saveData[user.id][pointPrefix + "points"]}`;
}
}
function setRarity(msg, setRarityPerson, amount) {
if (!msg.member.roles.cache.some(role => role.name === 'PokemonBotManager') && "" + msg.author.id !== process.env.AUTHOR_ID) {
return msg.channel.send("You are not a PokemonBotManager :eyes:");
}
if (checkOffLimits(msg)) {
return;
}
if (!setRarityPerson) {
return msg.channel.send("No user mentioned, please specify a person.");
}
// unnecessary but I'm keeping it here in case
setupDefaultsIfNecessary(saveData, setRarityPerson.id, setRarityPerson.globalName);
if (saveData["" + setRarityPerson.id]["rarityValue"] === 0 && amount < 0) {
msg.channel.send(`${setRarityPerson.globalName}'s rarity value is already at the minimum value of 0.`);
} else {
saveData["" + setRarityPerson.id]["rarityValue"] = amount;
msg.channel.send(`Set ${setRarityPerson.globalName}'s rarity value to ${amount}`);
save(saveData);
}
}
function increaseRarity(){
saveData = load();
console.log("triggering-rarity-increase");
const roleActions = [
{ threshold: 30, add: "Shiny", remove: ["Rare"] },
{ threshold: 14, add: "Rare", remove: ["Uncommon"] },
{ threshold: 7, add: "Uncommon", remove: [] },
];
const removeRolesBelowThreshold = ["Uncommon", "Rare", "Shiny"];
for (let user_id of Object.keys(saveData)) {
let user_id_num = Number(user_id);
// if the user_id is only numbers and the user wants to play
if (!isNaN(user_id_num) && saveData[user_id]["wants-to-play"] === true) {
const currentGuild = client.guilds.cache.find(g => g.id == process.env.GUILD_ID);
currentGuild.members.fetch(user_id).then(member => {
const userRarityValue = saveData[user_id]["rarityValue"];
// Fetch the roles once
const rolesCache = member.guild.roles.cache;
// Assign roles based on the user's rarity value
roleActions.forEach(action => {
if (userRarityValue >= action.threshold) {
let addRole = rolesCache.find(role => role.name === action.add);
if (addRole) member.roles.add(addRole);
action.remove.forEach(roleName => {
let removeRole = rolesCache.find(role => role.name === roleName);
if (removeRole) member.roles.remove(removeRole);
});
}
});
// Remove all roles if the rarity value is below 7
if (userRarityValue < 7) {
removeRolesBelowThreshold.forEach(roleName => {
let role = rolesCache.find(r => r.name === roleName);
if (role && member.roles.cache.has(role.id)) {
member.roles.remove(role);
}
});
}
// Increment the user's rarity value
saveData[user_id]["rarityValue"] += 1;
save(saveData);
}).catch(error => console.log(error));
}
}
}
// function to split up messages to send separately, to avoid issues with discord's limit of 2000 characters.
function splitMessage(str, size) {
const numChunks = Math.ceil(str.length / size);
const chunks = new Array(numChunks);
for (let i = 0, c = 0; i < numChunks; ++i, c += size) {
chunks[i] = str.substr(c, size);
}
return chunks;
}
// Function to send a long message in chunks
function sendLongMessage(channel, message) {
const messageChunks = splitMessage(message, Number(process.env.MAX_MESSAGE_LENGTH_BEFORE_SPLIT));
messageChunks.forEach(chunk => {
channel.send(chunk).catch(console.error);
});
}
function setupDefaultsIfNecessary(saveData, userID, userUsername){
try{
if (saveData[userID] === undefined) {
saveData[userID] = {"id": userID, "points": 0, "weekly_points": 0,"barnaby_points": 0,"weekly_barnaby_points": 0,"username":userUsername,"pokedex":{},"wants-to-play":true,"rarityValue":0,"AIPersonality":"Pokemon Announcer"};
save(saveData);
return true;
}
} catch(e) {
console.log("Error, player likely already registered");
return false;
}
}
function checkOffLimits(msg){
saveData = load();
let isOffLimits = false;
for (let Person of msg.mentions.users) {
let person = Person[1];
if (!saveData["" + person.id] || saveData["" + person.id]["wants-to-play"] == false){
isOffLimits = true;
break;
}
}
if (isOffLimits){
msg.channel.send("There was someone mentioned in your message that has not registered or has opted out from playing the game!");
msg.delete();
return true;
}
return false;
}
function load() {
try {
var saveData = JSON.parse(fs.readFileSync('./save-data.json', 'utf8'));
} catch (e) {
// init if no data found
var saveData = {
"SEASON_ID": "WINTER",
"SEASON_EMOJI": ":snowflake:",
"PLOT_ARMOR_PERSON_ID": undefined,
"DYNAMAX_PEOPLE_ID": [],
"VERMIN_WHISPERER_PERSON_ID": undefined,
"SWIPER_PEOPLE_ID": [],
"BOUNTY_PERSON_ID": undefined,
"catchCooldowns": {}
}
}
return saveData;
}
function save(saveData){
fs.writeFileSync('./save-data.json', JSON.stringify(saveData));
}
function awardPointsAndSendMessage(saveData, msg, catcherID, caughtPersonID, rarity, basePoints, multiplier) {
// If this is a PLOT ARMOR case
if (multiplier == null){
// STILL set the cooldown even after a failed catch
setCatchCooldown(saveData, msg.author.id, caughtPersonID);
return;
}
let pointsAwarded = basePoints * multiplier;
catcherUsername = saveData["" + catcherID]["username"];
caughtPersonUsername = saveData["" + caughtPersonID]["username"];
// Check if caughtPerson is a Barnaby catch
if (msg.mentions.users.size == 1 && ("" + caughtPersonID === process.env.BARNABY_ID)) {
// Find the amount of unique attachments in the catch message
const uniqueAttachments = new Set();
msg.attachments.forEach(attachment => {
uniqueAttachments.add(attachment.url);
});
let attachment_limit = Number(process.env.BARNABY_ATTACHMENT_LIMIT);
if (uniqueAttachments.size > attachment_limit) {
// Limit the attachments
msg.channel.send("Sorry! The limit for BARNABY attachments is " + attachment_limit + " so only " + attachment_limit + " of the provided attachments will count.")
}
// award points, making sure at least one point is added and 1 attachment = 1 point * multiplier
pointsAwarded = ((basePoints - 1) + Math.max(1, Math.min(uniqueAttachments.size, attachment_limit))) * multiplier;
// Keep track of barnaby points for perk reasons. Actual points are also recorded further below
saveData["" + catcherID]["barnaby_points"] += pointsAwarded;
saveData["" + catcherID]["weekly_barnaby_points"] += pointsAwarded;
// Send the catch AI message for Barnaby catch
askAI(`User @${catcherUsername} has caught ${uniqueAttachments.size} of a specially abundant type of Pokémon called "BARNABY" Pokémon and received ${pointsAwarded} points! Describe the catch, while playfully ridiculing the caught BARNABY personality, which is: ${saveData["" + caughtPersonID]["AIPersonality"]}`, catcherID)
.then(response => sendLongMessage(msg.channel,response));
} else {
// Send the catch AI message
askAI(`User @${catcherUsername} has caught the ${rarity}-rarity Pokémon @${caughtPersonUsername} and received ${pointsAwarded} points! Describe the catch, while playfully ridiculing the caught Pokémon's personality, which is: ${saveData[caughtPersonID]["AIPersonality"]}`, catcherID)
.then(response => sendLongMessage(msg.channel,response));
}
// Add points to the catcher
saveData["" + catcherID]["points"] += pointsAwarded;
saveData["" + catcherID]["weekly_points"] += pointsAwarded;
// Deduct half the base points from the caught person (minimum of 1)
const deduction = Math.max(Math.floor(basePoints / 2), 1);
// Only deduct TOTAL points
saveData["" + caughtPersonID]["points"] -= deduction;
// Update the catcher's Pokedex
const pokemonEntry = `${saveData["SEASON_EMOJI"]} ${caughtPersonUsername} ${saveData["SEASON_EMOJI"]}`;
// Increment the Pokedex entry (first initialize if necessary)
saveData["" + msg.author.id]["pokedex"][pokemonEntry] = saveData[msg.author.id]["pokedex"][pokemonEntry] || 0
saveData["" + msg.author.id]["pokedex"][pokemonEntry] += 1;
// Reset the rarity value of the caught person
saveData["" + caughtPersonID]["rarityValue"] = 0;
// Set the cooldown after a successful catch
setCatchCooldown(saveData, msg.author.id, caughtPersonID);
save(saveData);
}
function handleSpecialPerks(saveData, msg, catcherID, caughtPersonID) {
let multiplier = 1;
setupDefaultsIfNecessary(saveData, "" + msg.author.id, msg.author.globalName);
catcherUsername = saveData["" + catcherID]["username"];
caughtPersonUsername = saveData["" + caughtPersonID]["username"];
// Plot Armor Perk
if (caughtPersonID === saveData["PLOT_ARMOR_PERSON_ID"]) {
saveData["PLOT_ARMOR_PERSON_ID"] = "";
msg.channel.send(`@${caughtPersonUsername} has used their PLOT ARMOR perk to avoid being caught!`);
// Have to save here because of return
save(saveData);
return null; // Return null meaning the catch was unsuccessful
}
// Dynamax Perk
const dynamaxIndex = saveData["DYNAMAX_PEOPLE_ID"].indexOf("" + catcherID);
if (dynamaxIndex !== -1) {
multiplier *= 3;
// Use up Dynamax Perk
saveData["DYNAMAX_PEOPLE_ID"][dynamaxIndex] = undefined;
msg.channel.send(`@${catcherUsername} has used their DYNAMAX perk to triple their points from this catch!`);
}
// Vermin Whisperer Perk
if (caughtPersonID === saveData["VERMIN_WHISPERER_PERSON_ID"]) {
let deductedPoints = Number(process.env.VERMIN_STEAL_AMOUNT);
msg.channel.send(`@${catcherUsername} has caught @${caughtPersonUsername}, who has the VERMIN WHISPERER perk, which steals ${deductedPoints} point(s) from @${catcherUsername}'s TOTAL points!`);
saveData[caughtPersonID]["points"] += deductedPoints;
saveData[caughtPersonID]["weekly_points"] += deductedPoints;
// Only deduct from TOTAL points
saveData[catcherID]["points"] -= deductedPoints;
}
// Swiper Perk
const swiperIndex = saveData["SWIPER_PEOPLE_ID"].indexOf("" + catcherID);
if (swiperIndex !== -1) {
// Use up the Swiper perk
steal_percentage = Number(process.env.SWIPER_STEAL_PERCENTAGE);
saveData["SWIPER_PEOPLE_ID"][swiperIndex] = undefined;
let stolenPoints = Math.max(Math.floor(saveData[caughtPersonID]["points"] * (steal_percentage / 100)), 1);
msg.channel.send(`@${catcherUsername} has used their SWIPER perk to steal ${stolenPoints} (${steal_percentage}%) of @${caughtPersonUsername}'s TOTAL points!`);
saveData[catcherID]["points"] += stolenPoints;
saveData[catcherID]["weekly_points"] += stolenPoints;
// Only deduct from TOTAl points
saveData[caughtPersonID]["points"] -= stolenPoints;
}
// Bounty Perk
if (saveData["BOUNTY_PERSON_ID"] === "" + catcherID) {
multiplier *= 2;
msg.channel.send(`${catcherUsername} has the BOUNTY perk, which has doubled their points from this catch!`);
} else if (saveData["BOUNTY_PERSON_ID"] === caughtPersonID) {
multiplier *= 2;
saveData["BOUNTY_PERSON_ID"] = "";
msg.channel.send(`@${catcherUsername} has caught a Pokémon with the BOUNTY perk, doubling their points! @${caughtPersonUsername} has been caught, removing their BOUNTY perk.`);
}
save(saveData);
return multiplier;
}
// Function to check if a catch is allowed based on cooldowns
function isCatchAllowed(saveData, catcherId, caughtId) {
if (saveData["catchCooldowns"] === undefined){
saveData["catchCooldowns"] = {};
}
const key = `${catcherId}-${caughtId}`;
const reverseKey = `${caughtId}-${catcherId}`;
const nowInMinutes = Math.ceil(Date.now() / (60 * 1000));
const cooldownExpiry = saveData["catchCooldowns"][key] || saveData["catchCooldowns"][reverseKey];
if (!cooldownExpiry){
return { allowed: true };
}
else if (nowInMinutes < cooldownExpiry) {
const remainingTimeMinutes = cooldownExpiry - nowInMinutes;
// Return two data points: That the catch isn't allowed and also how much remaining time until the cooldown is over
return { allowed: false, remainingTime: remainingTimeMinutes };
}
// Remove the expired cooldown record to keep the database clean
delete saveData["catchCooldowns"][key];
delete saveData["catchCooldowns"][reverseKey];
save(saveData);
// Return that the catch is allowed
return { allowed: true };
}
// Function to set a cooldown for a catch
function setCatchCooldown(saveData, catcherId, caughtId) {
const cooldownDurationInMinutes = Number(process.env.COOLDOWN_MINUTES);
const key = `${catcherId}-${caughtId}`;
const reverseKey = `${caughtId}-${catcherId}`;
const nowInMinutes = Math.ceil(Date.now() / (60 * 1000));
const expiryTime = nowInMinutes + cooldownDurationInMinutes;
if (saveData["catchCooldowns"] === undefined){
saveData["catchCooldowns"] = {};
}
saveData["catchCooldowns"][key] = expiryTime;
saveData["catchCooldowns"][reverseKey] = expiryTime;
save(saveData);
}
function dubPlotArmor(saveData, PLOT_ARMOR_PERSON){
saveData["PLOT_ARMOR_PERSON_ID"] = "" + PLOT_ARMOR_PERSON.id;
return saveData;
}
function dubDynamax(saveData, DYNAMAX_PERSON) {
// Ensure saveData["DYNAMAX_PEOPLE_ID"] is initialized as an array
if (!Array.isArray(saveData["DYNAMAX_PEOPLE_ID"])) {
saveData["DYNAMAX_PEOPLE_ID"] = [];
}
saveData["DYNAMAX_PEOPLE_ID"].push("" + DYNAMAX_PERSON.id);
return saveData;
}
function dubVerminWhisperer(saveData, VERMIN_WHISPERER_PERSON){
saveData["VERMIN_WHISPERER_PERSON_ID"] = "" + VERMIN_WHISPERER_PERSON.id;
return saveData;
}
function dubSwiper(saveData, SWIPER_PERSON) {
// Ensure saveData["SWIPER_PEOPLE_ID"] is initialized as an array
if (!Array.isArray(saveData["SWIPER_PEOPLE_ID"])) {
saveData["SWIPER_PEOPLE_ID"] = [];
}
saveData["SWIPER_PEOPLE_ID"].push("" + SWIPER_PERSON.id);
return saveData;
}
function dubBounty(saveData, BOUNTY_PERSON){
saveData["BOUNTY_PERSON_ID"] = "" + BOUNTY_PERSON.id;
return saveData;
}
async function perkUpdate() {
saveData = load();
try {
const pokemon_channel = await client.channels.fetch(process.env.POKEMON_CHANNEL_ID);
if (!pokemon_channel) {
console.error("Pokemon channel not found.");
return;
}
// Filter and validate
const users = Object.values(saveData)
.filter(user => user && typeof user === 'object' && user["wants-to-play"]);
if (users.length === 0) {
await pokemon_channel.send("No users found");
return;
}
// Get the top users for various categories
const topUsersByPoints = users.sort((a, b) => b["points"] - a["points"]).slice(0, 10);
const topUsersByBarnabyPoints = users.sort((a, b) => b["barnaby_points"] - a["barnaby_points"]).slice(0, 10);
const topUsersByWeeklyPoints = users.sort((a, b) => b["weekly_points"] - a["weekly_points"]).slice(0, 5);
const topUsersByWeeklyBarnabyPoints = users.sort((a, b) => b["weekly_barnaby_points"] - a["weekly_barnaby_points"]).slice(0, 5);
const topUsersByRarity = users.map(user => ({ ...user, rarity: user["rarityValue"] || 0 })).sort((a, b) => b["rarityValue"] - a["rarityValue"]).slice(0, 5);
let messageContent = "**------------LEADERBOARD UPDATE------------**\n\n";
// Append leaderboard messages
messageContent += "Here is the overall TOTAL point leaderboard!:\n" +
topUsersByPoints.map((user, index) => `${index + 1}. **${user["username"]}**: ${user["points"]}`).join('\n') + "\n\n";
messageContent += "Here is the overall BARNABY point leaderboard!:\n" +
topUsersByBarnabyPoints.map((user, index) => `${index + 1}. **${user["username"]}**: ${user["barnaby_points"]}`).join('\n') + "\n\n";
messageContent += "Here is last week's overall point leaderboard!:\n" +
topUsersByWeeklyPoints.map((user, index) => `${index + 1}. **${user["username"]}**: ${user["weekly_points"]}`).join('\n') + "\n\n";
messageContent += "Here is last week's BARNABY point leaderboard!:\n" +
topUsersByWeeklyBarnabyPoints.map((user, index) => `${index + 1}. **${user["username"]}**: ${user["weekly_barnaby_points"]}`).join('\n') + "\n\n";
messageContent += "Here is last week's RARITY leaderboard!:\n" +
topUsersByRarity.map((user, index) => `${index + 1}. **${user["username"]}**: ${user["rarityValue"]}`).join('\n') + "\n\n";
messageContent += "**--------------PERKS AWARDED--------------**\n\n";
// Plot Armor
const topWeeklyUser = topUsersByWeeklyPoints[0];
if (topWeeklyUser) {
saveData = dubPlotArmor(saveData, topWeeklyUser);
messageContent += `Winner of the **PLOT ARMOR** perk:\n- *${topWeeklyUser["username"]}*\n\n`;
}
saveData["DYNAMAX_PEOPLE_ID"] = [];
// Dynamax
messageContent += "Winners of the **DYNAMAX** perk:\n";
topUsersByWeeklyPoints.slice(0, 3).forEach((user, index) => {
saveData = dubDynamax(saveData, user);
messageContent += `${index + 1}. *${user["username"]}*\n`;
});
messageContent += "\n";
// Vermin Whisperer
const topWeeklyBarnabyUser = topUsersByWeeklyBarnabyPoints[0];
if (topWeeklyBarnabyUser) {
saveData = dubVerminWhisperer(saveData, topWeeklyBarnabyUser);
messageContent += `Winner of the **VERMIN WHISPERER** perk:\n- *${topWeeklyBarnabyUser["username"]}*\n\n`;
}
// Swiper
saveData["SWIPER_PEOPLE_ID"] = [];
messageContent += "Winners of the **SWIPER** perk:\n";
topUsersByWeeklyBarnabyPoints.slice(0, 3).forEach((user, index) => {
saveData = dubSwiper(saveData, user);
messageContent += `${index + 1}. *${user["username"]}*\n`;
});
messageContent += "\n";
// Bounty
const topRarityValueUsers = users.map(user => user["rarityValue"] || 0);
let topRarityValue = Math.max(...topRarityValueUsers);
const tiedUsers = users.filter(user => user["rarityValue"] === topRarityValue);
if (tiedUsers.length > 0) {
const bountyWinner = tiedUsers[Math.floor(Math.random() * tiedUsers.length)];
saveData = dubBounty(saveData, bountyWinner);
messageContent += `Winner of the **BOUNTY** perk:\n- *${bountyWinner["username"]}*\n\n`;
}
// Clear weekly points and cooldowns
users.forEach(user => {
user["weekly_points"] = 0;
user["weekly_barnaby_points"] = 0;
});
saveData["catchCooldowns"] = {};
save(saveData);
sendLongMessage(pokemon_channel, messageContent);
console.log("Weekly points have been cleared for all players.");
} catch (error) {
console.error("An error occurred during the tournament update:", error);
}
}
// Export all the functions needed
module.exports = {
express,
app,
fs,
cron,
openai,
discord,
client,
saveData,
cmd,
askAI,
adjustPoints,
setRarity,
increaseRarity,
sendLongMessage,
setupDefaultsIfNecessary,
checkOffLimits,
load,
save,
awardPointsAndSendMessage,
handleSpecialPerks,
isCatchAllowed,
perkUpdate
};