Assorted db changes (#333)
* postgres: use transaction-scoped sql for upgrade
* database: combine fixGuild and addGuild into getGuild
* postgres, sqlite: simplify upgrade()
* allow running commands in DMs without prefix
this functionality was broken in
16095c0256
but is now fixed
* allow running esmBot without a database
Before this change, the only way to run esmBot without a database is to use the
dummy database driver which is broken but fails silently. THis can lead to a
confusing user experience. For instance, using `&command disable` with the
dummy database driver will tell you that the command has been disabled even
though it has not been.
This change adds support for running esmBot with no database driver by leaving
the DB= config option empty, and explicitly telling the user that some
functionality is now unavailable rather than failing silently like the dummy
driver.
* remove dummy database driver
This commit is contained in:
parent
345b525188
commit
ed25116851
18 changed files with 130 additions and 177 deletions
|
@ -46,6 +46,7 @@ class BroadcastCommand extends Command {
|
|||
|
||||
static description = "Broadcasts a playing message until the command is run again or the bot restarts";
|
||||
static adminOnly = true;
|
||||
static dbRequired = true;
|
||||
}
|
||||
|
||||
export default BroadcastCommand;
|
|
@ -47,6 +47,7 @@ class ChannelCommand extends Command {
|
|||
static arguments = ["[enable/disable]", "{id}"];
|
||||
static slashAllowed = false;
|
||||
static directAllowed = false;
|
||||
static dbRequired = true;
|
||||
}
|
||||
|
||||
export default ChannelCommand;
|
||||
|
|
|
@ -38,6 +38,7 @@ class CommandCommand extends Command {
|
|||
static arguments = ["[enable/disable]", "[command]"];
|
||||
static slashAllowed = false;
|
||||
static directAllowed = false;
|
||||
static dbRequired = true;
|
||||
}
|
||||
|
||||
export default CommandCommand;
|
||||
|
|
|
@ -48,6 +48,7 @@ class CountCommand extends Command {
|
|||
static description = "Gets how many times every command was used";
|
||||
static arguments = ["{mention/id}"];
|
||||
static aliases = ["counts"];
|
||||
static dbRequired = true;
|
||||
}
|
||||
|
||||
export default CountCommand;
|
|
@ -9,11 +9,15 @@ const tips = ["You can change the bot's prefix using the prefix command.", "Imag
|
|||
|
||||
class HelpCommand extends Command {
|
||||
async run() {
|
||||
const { prefix } = this.guild ? await database.getGuild(this.guild.id) : "N/A";
|
||||
let prefix;
|
||||
if (this.guild && database) {
|
||||
prefix = (await database.getGuild(this.guild.id)).prefix;
|
||||
} else {
|
||||
prefix = process.env.PREFIX;
|
||||
}
|
||||
if (this.args.length !== 0 && (collections.commands.has(this.args[0].toLowerCase()) || collections.aliases.has(this.args[0].toLowerCase()))) {
|
||||
const command = collections.aliases.get(this.args[0].toLowerCase()) ?? this.args[0].toLowerCase();
|
||||
const info = collections.info.get(command);
|
||||
const counts = await database.getCounts();
|
||||
const embed = {
|
||||
embeds: [{
|
||||
author: {
|
||||
|
@ -27,10 +31,6 @@ class HelpCommand extends Command {
|
|||
fields: [{
|
||||
name: "Aliases",
|
||||
value: info.aliases.length !== 0 ? info.aliases.join(", ") : "None"
|
||||
}, {
|
||||
name: "Times Used",
|
||||
value: counts[command],
|
||||
inline: true
|
||||
}, {
|
||||
name: "Parameters",
|
||||
value: command === "tags" ? "[name]" : (info.params ? (info.params.length !== 0 ? info.params.join(" ") : "None") : "None"),
|
||||
|
@ -38,6 +38,13 @@ class HelpCommand extends Command {
|
|||
}]
|
||||
}]
|
||||
};
|
||||
if (database) {
|
||||
embed.embeds[0].fields.push({
|
||||
name: "Times used",
|
||||
value: (await database.getCounts())[command],
|
||||
inline: true
|
||||
});
|
||||
}
|
||||
if (info.flags.length !== 0) {
|
||||
const flagInfo = [];
|
||||
for (const flag of info.flags) {
|
||||
|
@ -92,7 +99,7 @@ class HelpCommand extends Command {
|
|||
},
|
||||
fields: [{
|
||||
name: "Prefix",
|
||||
value: this.guild ? prefix : "N/A"
|
||||
value: prefix
|
||||
}, {
|
||||
name: "Tip",
|
||||
value: random(tips)
|
||||
|
|
|
@ -6,6 +6,9 @@ class PrefixCommand extends Command {
|
|||
if (!this.guild) return `The current prefix is \`${process.env.PREFIX}\`.`;
|
||||
const guild = await database.getGuild(this.guild.id);
|
||||
if (this.args.length !== 0) {
|
||||
if (!database) {
|
||||
return "Setting a per-guild prefix is not possible on a stateless instance of esmBot!"
|
||||
}
|
||||
const owners = process.env.OWNER.split(",");
|
||||
if (!this.member.permissions.has("ADMINISTRATOR") && !owners.includes(this.member.id)) {
|
||||
this.success = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue