Fix sqlite guild registration, fix starting status

This commit is contained in:
Essem 2022-09-28 23:11:05 -05:00
parent b636fe9ebe
commit cee458cef1
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
5 changed files with 9 additions and 9 deletions

4
app.js
View file

@ -154,9 +154,9 @@ const client = new Client({
concurrency: "auto",
maxShards: "auto",
presence: {
status: "dnd",
status: "idle",
activities: [{
type: "GAME",
type: 0,
name: "Starting esmBot..."
}]
},

View file

@ -5,5 +5,5 @@ import { log } from "../utils/logger.js";
export default async (client, guild) => {
log(`[GUILD JOIN] ${guild.name} (${guild.id}) added the bot.`);
const guildDB = await db.getGuild(guild.id);
if (!guildDB) await db.addGuild(guild);
if (!guildDB) await db.addGuild(guild.id);
};

View file

@ -23,7 +23,7 @@ export async function editTag() {}
export async function setPrefix() {}
export async function addGuild(guild) {
return {
id: guild.id,
id: guild,
tags: {},
prefix: process.env.PREFIX,
disabled: [],

View file

@ -155,9 +155,9 @@ export async function addGuild(guild) {
}
export async function fixGuild(guild) {
const guildDB = await sql`SELECT exists(SELECT 1 FROM guilds WHERE guild_id = ${guild.id})`;
const guildDB = await sql`SELECT exists(SELECT 1 FROM guilds WHERE guild_id = ${guild})`;
if (!guildDB[0].exists) {
logger.log(`Registering guild database entry for guild ${guild.id}...`);
logger.log(`Registering guild database entry for guild ${guild}...`);
return await this.addGuild(guild);
}
}

View file

@ -69,12 +69,12 @@ export async function upgrade(logger) {
export async function fixGuild(guild) {
let guildDB;
try {
guildDB = connection.prepare("SELECT * FROM guilds WHERE guild_id = ?").get(guild.id);
guildDB = connection.prepare("SELECT * FROM guilds WHERE guild_id = ?").get(guild);
} catch {
connection.prepare("CREATE TABLE guilds ( guild_id VARCHAR(30) NOT NULL PRIMARY KEY, prefix VARCHAR(15) NOT NULL, disabled text NOT NULL, disabled_commands text NOT NULL )").run();
}
if (!guildDB) {
logger.log(`Registering guild database entry for guild ${guild.id}...`);
logger.log(`Registering guild database entry for guild ${guild}...`);
return await this.addGuild(guild);
}
}
@ -160,7 +160,7 @@ export async function addGuild(guild) {
const query = await this.getGuild(guild);
if (query) return query;
const guildObject = {
id: guild.id,
id: guild,
prefix: process.env.PREFIX,
disabled: "[]",
disabledCommands: "[]"