Spaces:
Running
Running
Update bot.js
Browse files
bot.js
CHANGED
|
@@ -1,20 +1,8 @@
|
|
| 1 |
"use strict";
|
| 2 |
-
const { Client, GatewayIntentBits, MessageFlags
|
| 3 |
-
const { Agent } = require("undici");
|
| 4 |
const db = require("./db");
|
| 5 |
|
| 6 |
-
//
|
| 7 |
-
const botAgent = new Agent({
|
| 8 |
-
connect: {
|
| 9 |
-
timeout: 15000, // Increase connect timeout to 15s
|
| 10 |
-
keepAlive: true,
|
| 11 |
-
keepAliveTimeout: 30000,
|
| 12 |
-
},
|
| 13 |
-
bodyTimeout: 0, // Prevent body timeout issues on slow networks
|
| 14 |
-
headersTimeout: 15000,
|
| 15 |
-
requestTimeout: 15000,
|
| 16 |
-
});
|
| 17 |
-
|
| 18 |
const client = new Client({
|
| 19 |
intents: [
|
| 20 |
GatewayIntentBits.Guilds,
|
|
@@ -22,12 +10,11 @@ const client = new Client({
|
|
| 22 |
GatewayIntentBits.MessageContent
|
| 23 |
],
|
| 24 |
rest: {
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
retries: 5, // More retries for flaky networks
|
| 28 |
},
|
| 29 |
ws: {
|
| 30 |
-
large_threshold: 50, // Reduce initial load
|
| 31 |
}
|
| 32 |
});
|
| 33 |
|
|
@@ -47,40 +34,31 @@ client.on("messageCreate", (message) => {
|
|
| 47 |
return;
|
| 48 |
}
|
| 49 |
|
| 50 |
-
// !roster-add @User Role [Team Name]
|
| 51 |
if (content.startsWith(`${prefix}roster-add`)) {
|
| 52 |
-
const
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
}
|
| 57 |
-
|
| 58 |
const user = message.mentions.users.first();
|
| 59 |
if (!user) {
|
| 60 |
-
message.reply("
|
| 61 |
return;
|
| 62 |
}
|
| 63 |
|
| 64 |
-
//
|
| 65 |
-
|
| 66 |
-
// We assume the second arg is start of role, third could be team if specified
|
| 67 |
-
const roleParts = [];
|
| 68 |
-
let teamName = "General";
|
| 69 |
-
|
| 70 |
-
// Simple heuristic: if last arg looks like a team (not a role), but for now let's keep it simple:
|
| 71 |
-
// !roster-add @User Role
|
| 72 |
-
// We will treat everything after @User as the role, unless "in" is used
|
| 73 |
-
const fullText = content.slice(`${prefix}roster-add`.length).trim();
|
| 74 |
-
const match = fullText.match(/<@\d+>\s+(.+?)(?:\s+in\s+(.+))?$/);
|
| 75 |
|
| 76 |
let role = "Member";
|
| 77 |
-
teamName = "General";
|
| 78 |
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
| 82 |
} else {
|
| 83 |
-
role =
|
| 84 |
}
|
| 85 |
|
| 86 |
const userTag = user.tag;
|
|
|
|
| 1 |
"use strict";
|
| 2 |
+
const { Client, GatewayIntentBits, MessageFlags } = require("discord.js");
|
|
|
|
| 3 |
const db = require("./db");
|
| 4 |
|
| 5 |
+
// Default configuration is robust enough for most networks
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
const client = new Client({
|
| 7 |
intents: [
|
| 8 |
GatewayIntentBits.Guilds,
|
|
|
|
| 10 |
GatewayIntentBits.MessageContent
|
| 11 |
],
|
| 12 |
rest: {
|
| 13 |
+
timeout: 15000, // 15s timeout
|
| 14 |
+
retries: 5, // Retry up to 5 times
|
|
|
|
| 15 |
},
|
| 16 |
ws: {
|
| 17 |
+
large_threshold: 50, // Reduce initial load for faster startup
|
| 18 |
}
|
| 19 |
});
|
| 20 |
|
|
|
|
| 34 |
return;
|
| 35 |
}
|
| 36 |
|
| 37 |
+
// !roster-add @User Role [in Team Name]
|
| 38 |
if (content.startsWith(`${prefix}roster-add`)) {
|
| 39 |
+
const fullText = content.slice(`${prefix}roster-add`.length).trim();
|
| 40 |
+
|
| 41 |
+
// Match: <@123456789> Role Name in Team Name
|
| 42 |
+
// Or: <@123456789> Role Name
|
|
|
|
|
|
|
| 43 |
const user = message.mentions.users.first();
|
| 44 |
if (!user) {
|
| 45 |
+
message.reply("Usage: `!roster-add @User Role [in Team Name]`");
|
| 46 |
return;
|
| 47 |
}
|
| 48 |
|
| 49 |
+
// Remove the mention from the string to parse the rest
|
| 50 |
+
const rest = fullText.replace(/<@\d+>\s?/, "").trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
let role = "Member";
|
| 53 |
+
let teamName = "General";
|
| 54 |
|
| 55 |
+
// Check for " in " to split role and team
|
| 56 |
+
const inIndex = rest.lastIndexOf(" in ");
|
| 57 |
+
if (inIndex > -1) {
|
| 58 |
+
role = rest.substring(0, inIndex).trim() || "Member";
|
| 59 |
+
teamName = rest.substring(inIndex + 4).trim() || "General";
|
| 60 |
} else {
|
| 61 |
+
role = rest || "Member";
|
| 62 |
}
|
| 63 |
|
| 64 |
const userTag = user.tag;
|