Spaces:
Runtime error
Runtime error
Create bot.js
Browse files
bot.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"use strict";
|
| 2 |
+
const { Client, GatewayIntentBits, MessageFlags, EmbedBuilder } = require("discord.js");
|
| 3 |
+
const db = require("./db");
|
| 4 |
+
|
| 5 |
+
const client = new Client({
|
| 6 |
+
intents: [
|
| 7 |
+
GatewayIntentBits.Guilds,
|
| 8 |
+
GatewayIntentBits.GuildMessages,
|
| 9 |
+
GatewayIntentBits.MessageContent
|
| 10 |
+
]
|
| 11 |
+
});
|
| 12 |
+
|
| 13 |
+
client.once("ready", () => {
|
| 14 |
+
console.log(`[BOT] Logged in as ${client.user.tag}`);
|
| 15 |
+
console.log(`[BOT] Serving ${client.guilds.cache.size} guilds`);
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
client.on("messageCreate", (message) => {
|
| 19 |
+
if (message.author.bot) return;
|
| 20 |
+
|
| 21 |
+
const content = message.content.trim();
|
| 22 |
+
const prefix = "!";
|
| 23 |
+
|
| 24 |
+
if (content === `${prefix}ping`) {
|
| 25 |
+
message.reply(`Pong! Latency: ${client.ws.ping}ms`);
|
| 26 |
+
return;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
// !roster-add @User Role [Team Name]
|
| 30 |
+
if (content.startsWith(`${prefix}roster-add`)) {
|
| 31 |
+
const args = content.split(/\s+/).slice(1); // skip command
|
| 32 |
+
if (args.length < 2) {
|
| 33 |
+
message.reply("Usage: `!roster-add @User Role [Team Name]`");
|
| 34 |
+
return;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
const user = message.mentions.users.first();
|
| 38 |
+
if (!user) {
|
| 39 |
+
message.reply("You must mention a user.");
|
| 40 |
+
return;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
// Parse role and optional team
|
| 44 |
+
// Format: !roster-add @User Role Name [Optional Team Name]
|
| 45 |
+
// We assume the second arg is start of role, third could be team if specified
|
| 46 |
+
const roleParts = [];
|
| 47 |
+
let teamName = "General";
|
| 48 |
+
|
| 49 |
+
// Simple heuristic: if last arg looks like a team (not a role), but for now let's keep it simple:
|
| 50 |
+
// !roster-add @User Role
|
| 51 |
+
// We will treat everything after @User as the role, unless "in" is used
|
| 52 |
+
const fullText = content.slice(`${prefix}roster-add`.length).trim();
|
| 53 |
+
const match = fullText.match(/<@\d+>\s+(.+?)(?:\s+in\s+(.+))?$/);
|
| 54 |
+
|
| 55 |
+
let role = "Member";
|
| 56 |
+
teamName = "General";
|
| 57 |
+
|
| 58 |
+
if (match) {
|
| 59 |
+
role = match[1] || "Member";
|
| 60 |
+
if (match[2]) teamName = match[2];
|
| 61 |
+
} else {
|
| 62 |
+
role = fullText;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
const userTag = user.tag;
|
| 66 |
+
db.addRoster(teamName, userTag, role);
|
| 67 |
+
message.reply(`✅ Added **${userTag}** as **${role}** to **${teamName}**.`);
|
| 68 |
+
}
|
| 69 |
+
});
|
| 70 |
+
|
| 71 |
+
client.on("interactionCreate", async (interaction) => {
|
| 72 |
+
if (!interaction.isChatInputCommand()) return;
|
| 73 |
+
|
| 74 |
+
if (interaction.commandName === "ping") {
|
| 75 |
+
await interaction.reply({ content: `Latency: ${client.ws.ping}ms`, flags: MessageFlags.Ephemeral });
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
if (interaction.commandName === "roster-add") {
|
| 79 |
+
const team = interaction.options.getString("team") || "General";
|
| 80 |
+
const user = interaction.options.getUser("user");
|
| 81 |
+
const role = interaction.options.getString("role") || "Member";
|
| 82 |
+
const userTag = user ? user.tag : "Unknown";
|
| 83 |
+
|
| 84 |
+
db.addRoster(team, userTag, role);
|
| 85 |
+
await interaction.reply({ content: `✅ Added **${userTag}** as **${role}** to **${team}**.`, flags: MessageFlags.Ephemeral });
|
| 86 |
+
}
|
| 87 |
+
});
|
| 88 |
+
|
| 89 |
+
module.exports = { client };
|