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

V0.1.0 - Initial

This is the first release of Group Up.  Expect errors and poor input parsing for time.

Documentation is coming soon™️
This commit is contained in:
Ean Milligan (Bastion)
2021-05-30 17:04:58 -04:00
parent 846818c831
commit d60d1ff829
19 changed files with 2265 additions and 0 deletions

67
db/initialize.ts Normal file
View File

@ -0,0 +1,67 @@
// 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,
});
console.log("Attempting to create DB");
await dbClient.execute(`CREATE SCHEMA IF NOT EXISTS ${config.db.name};`);
await dbClient.execute(`USE ${config.db.name}`);
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;`);
console.log("Tables dropped");
console.log("Attempting to create table command_cnt");
await dbClient.execute(`
CREATE TABLE command_cnt (
command char(20) NOT NULL,
count bigint unsigned NOT NULL DEFAULT 0,
PRIMARY KEY (command),
UNIQUE KEY command_cnt_command_UNIQUE (command)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`);
console.log("Table created");
console.log("Attempt creating increment Stored Procedure");
await dbClient.execute(`
CREATE PROCEDURE INC_CNT(
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;
END
`);
console.log("Stored Procedure created");
console.log("Attempting to create table guild_prefix");
await dbClient.execute(`
CREATE TABLE guild_prefix (
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");
await dbClient.close();
console.log("Done!");

30
db/populateDefaults.ts Normal file
View File

@ -0,0 +1,30 @@
// This file will populate the tables with default values
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,
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 (let i = 0; i < commands.length; i++) {
await dbClient.execute("INSERT INTO command_cnt(command) values(?)", [commands[i]]).catch(e => {
console.log(`Failed to insert into database`, e);
});
}
console.log("Insertion done");
await dbClient.close();
console.log("Done!");