1
1
mirror of https://github.com/Burn-E99/GroupUp.git synced 2026-01-06 11:27:54 -05:00

Slight rework to commands, db redesign, setup command almost done

This commit is contained in:
Ean Milligan (Bastion)
2023-01-28 20:58:24 -05:00
parent 9cb615e68d
commit a43fade7d5
13 changed files with 427 additions and 99 deletions

View File

@ -1,21 +1,8 @@
// This file will create all tables for the artificer schema
// DATA WILL BE LOST IF DB ALREADY EXISTS, RUN AT OWN RISK
import {
// MySQL deps
Client,
} from '../deps.ts';
import { LOCALMODE } from '../flags.ts';
import config from '../config.ts';
// Log into the MySQL DB
const dbClient = await new Client().connect({
hostname: LOCALMODE ? config.db.localhost : config.db.host,
port: config.db.port,
username: config.db.username,
password: config.db.password,
});
import { dbClient } from '../src/db.ts';
console.log('Attempting to create DB');
await dbClient.execute(`CREATE SCHEMA IF NOT EXISTS ${config.db.name};`);
@ -25,9 +12,7 @@ console.log('DB created');
console.log('Attempt to drop all tables');
await dbClient.execute(`DROP PROCEDURE IF EXISTS INC_CNT;`);
await dbClient.execute(`DROP TABLE IF EXISTS command_cnt;`);
await dbClient.execute(`DROP TABLE IF EXISTS guild_prefix;`);
await dbClient.execute(`DROP TABLE IF EXISTS guild_mod_role;`);
await dbClient.execute(`DROP TABLE IF EXISTS guild_clean_channel;`);
await dbClient.execute(`DROP TABLE IF EXISTS guild_settings;`);
console.log('Tables dropped');
console.log('Attempting to create table command_cnt');
@ -47,41 +32,21 @@ await dbClient.execute(`
IN cmd CHAR(20)
)
BEGIN
declare oldcnt bigint unsigned;
set oldcnt = (SELECT count FROM command_cnt WHERE command = cmd);
UPDATE command_cnt SET count = oldcnt + 1 WHERE command = cmd;
declare oldCnt bigint unsigned;
set oldCnt = (SELECT count FROM command_cnt WHERE command = cmd);
UPDATE command_cnt SET count = oldCnt + 1 WHERE command = cmd;
END
`);
console.log('Stored Procedure created');
console.log('Attempting to create table guild_prefix');
console.log('Attempting to create table guild_settings');
await dbClient.execute(`
CREATE TABLE guild_prefix (
CREATE TABLE guild_settings (
guildId bigint unsigned NOT NULL,
prefix char(10) NOT NULL,
PRIMARY KEY (guildid),
UNIQUE KEY guild_prefix_guildid_UNIQUE (guildid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`);
console.log('Table created');
console.log('Attempting to create table guild_mod_role');
await dbClient.execute(`
CREATE TABLE guild_mod_role (
guildId bigint unsigned NOT NULL,
roleId bigint unsigned NOT NULL,
PRIMARY KEY (guildid),
UNIQUE KEY guild_mod_role_guildid_UNIQUE (guildid)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`);
console.log('Table created');
console.log('Attempting to create table guild_clean_channel');
await dbClient.execute(`
CREATE TABLE guild_clean_channel (
guildId bigint unsigned NOT NULL,
channelId bigint unsigned NOT NULL,
PRIMARY KEY (guildid, channelId)
lfgChannelId bigint unsigned NOT NULL,
managerRoleId bigint unsigned NOT NULL,
logChannelId bigint unsigned NOT NULL,
PRIMARY KEY (guildId, lfgChannelId)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`);
console.log('Table created');

View File

@ -1,26 +1,15 @@
// This file will populate the tables with default values
import {
// MySQL deps
Client,
} from '../deps.ts';
import { dbClient } from '../src/db.ts';
import { LOCALMODE } from '../flags.ts';
import config from '../config.ts';
// Log into the MySQL DB
const dbClient = await new Client().connect({
hostname: LOCALMODE ? config.db.localhost : config.db.host,
port: config.db.port,
db: config.db.name,
username: config.db.username,
password: config.db.password,
});
console.log('Attempting to insert default commands into command_cnt');
const commands = ['ping', 'help', 'info', 'version', 'report', 'privacy', 'lfg', 'prefix'];
for (const command of commands) {
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [command]).catch((e) => {
console.log('Attempting to insert default actions into command_cnt');
const actions = [
'cmd-setup',
'cmd-info',
'cmd-report',
];
for (const action of actions) {
await dbClient.execute('INSERT INTO command_cnt(command) values(?)', [action]).catch((e) => {
console.log(`Failed to insert into database`, e);
});
}