1+ // add a leave blank for your own data, only MR can see other peoples database when I figure out subcommands
2+
3+ /* import { SlashCommandBuilder, EmbedBuilder, ChatInputCommandInteraction } from "discord.js";
4+ import mysql from "mysql";
5+ import { KOGBot } from "index.ts";
6+ import { SlashCommand } from "main.d.ts";
7+ import config from "../../config"
8+
9+ const connection = mysql.createConnection({
10+ host: config.database.host,
11+ port: config.database.port,
12+ user: config.database.user,
13+ password: config.database.password,
14+ database: config.database.schema
15+ });
16+
17+ class GetDataCommand implements SlashCommand {
18+ name = "data";
19+ description = "Database command for KOG. ";
20+ subcommands = []; Subcommandds (data change, data add, data check)
21+ parameters = [];
22+ dev = true; // dev for now
23+ kogBot: KOGBot;
24+
25+ constructor(kogBot: KOGBot) {
26+ this.kogBot = kogBot;
27+ }
28+
29+ async execute(interaction: ChatInputCommandInteraction): Promise<void> {
30+ try {
31+ const user = interaction.user;
32+ const userId = interaction.user.id; // Needed for DB
33+
34+ connection.query('SELECT * FROM KOGDB WHERE userid = ?', [userId], async (err, results) => {
35+ if (err) {
36+ console.error(err);
37+ const embedError = new EmbedBuilder()
38+ .setColor("#E73A3A")
39+ .setTitle("Database Error")
40+ .setDescription("An error occurred while trying to retrieve your data.");
41+ await interaction.reply({ embeds: [embedError] });
42+ return;
43+ }
44+
45+ if (results.length > 0) {
46+
47+ const { eventsAttended, eventsHosted } = results[0];
48+
49+ const embed = new EmbedBuilder()
50+ .setColor("#9033FF")
51+ .setTitle(`Information Retrieved on ${user.username}`)
52+ .addFields(
53+ { name: "Events Attended", value: eventsAttended.toString() },
54+ { name: "Events Hosted", value: eventsHosted.toString() }
55+ );
56+
57+ await interaction.reply({ embeds: [embed] });
58+
59+ } else {
60+ const embedFail = new EmbedBuilder()
61+ .setColor("#E73A3A")
62+ .setTitle("No Data Found")
63+ .setDescription("You need to be logged for an event before you can retrieve your data.");
64+
65+ await interaction.reply({ embeds: [embedFail] });
66+ }
67+ });
68+
69+ } catch (error) {
70+ console.error(error);
71+ const embedError = new EmbedBuilder()
72+ .setColor("#E73A3A")
73+ .setTitle("Error")
74+ .setDescription("An error occurred while trying to retrieve your data.");
75+ await interaction.reply({ embeds: [embedError] });
76+ }
77+ }
78+ }
79+
80+ export default GetDataCommand;
81+
82+ */
0 commit comments