forked from carmex/SlackCountingBot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.js
More file actions
99 lines (86 loc) · 3.71 KB
/
utils.js
File metadata and controls
99 lines (86 loc) · 3.71 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
const {isPrime} = require('./mathOperations');
async function getStatsMessage(client, stats) {
let message = '📊 Counting Game Stats 📊\n\n';
message += `Highest count: ${stats.highestCount}\n`;
if (stats.highestCountTimestamp) {
const date = new Date(stats.highestCountTimestamp);
const options = {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hour12: false, // Use 24-hour clock
timeZone: 'UTC' // Use the UTC+0 timezone
};
message += `Achieved on: ${date.toLocaleString('en-US', options)} UTC\n`;
}
message += `Total successful counts: ${stats.totalSuccessfulCounts}\n\n`;
message += '🏆 Top Counters:\n';
const sortedUsers = Object.entries(stats.userStats)
.sort(([, a], [, b]) => b.successful - a.successful)
.slice(0, 5);
for (const [userId, userStats] of sortedUsers) {
try {
const userInfo = await client.users.info({user: userId});
const username = userInfo.user.username || userInfo.user.name;
const avgComplexity = userStats.countWithComplexity > 0
? (userStats.totalComplexity / userStats.countWithComplexity).toFixed(2)
: 'N/A';
message += `<@${userId}>: ${userStats.successful} (${userStats.unsuccessful} fails, Avg Complexity: ${avgComplexity}`;
if (userStats.primes) message += `, Primes: ${userStats.primes}`;
if (userStats.perfectSquares) message += `, Perfect Squares: ${userStats.perfectSquares}`;
message += ')\n';
} catch (error) {
message += `${username}: ${userStats.successful} (${userStats.unsuccessful} fails)\n`;
}
}
message += '\n🎯 Milestones:\n';
for (const [milestone, userId] of Object.entries(stats.milestones)) {
try {
const userInfo = await client.users.info({user: userId});
const username = userInfo.user.username || userInfo.user.name;
message += `${milestone}: <@${userId}>\n`;
} catch (error) {
message += `${milestone}: ${username}>\n`;
}
}
message += '\n🧮 Most Complicated Operation:\n';
if (stats.mostComplicatedOperation.user) {
try {
const userInfo = await client.users.info({user: stats.mostComplicatedOperation.user});
const username = userInfo.user.username || userInfo.user.name;
message += `<@${stats.mostComplicatedOperation.user}>: ${stats.mostComplicatedOperation.expression} (Complexity: ${stats.mostComplicatedOperation.complexity})\n`;
} catch (error) {
message += `${username}>: ${stats.mostComplicatedOperation.expression} (Complexity: ${stats.mostComplicatedOperation.complexity})\n`;
}
} else {
message += 'No complicated operations yet!\n';
}
return message;
}
function getHelpMessage() {
return `
🔢 Welcome to the Counting Game! 🔢
Rules:
1. Count up from 1, one number at a time.
2. Base 10.
3. NO BOTS ALLOWED!!!
4. Each person can only count once in a row.
5. If someone makes a mistake, the count continues without resetting.
You can use basic math operations to represent numbers:
• Addition: 2+3
• Subtraction: 10-7
• Multiplication: 4*3
• Division: 15/3
• Exponents: 2^3
• Square roots and cube roots: √9 or sqrt(9), cbrt(27)
Commands:
• !stats or /counting-stats - View game statistics
• !help or /counting-help - Show this help message
• !eval [expression] or /eval [expression] - Evaluate an expression
Have fun counting! 🎉
`;
}
module.exports = {getStatsMessage, getHelpMessage};