Remove creation date from mkdocs, added ability to limit owner commands to certain server, don't append help command to end of playing message if classic commands are disabled, fix interaction upload size

This commit is contained in:
Essem 2022-09-01 10:40:55 -05:00
parent 3477f5c39f
commit 603e732704
No known key found for this signature in database
GPG Key ID: 7D497397CC3A2A8C
14 changed files with 40 additions and 24 deletions

View File

@ -53,4 +53,7 @@ API_TYPE=none
# If API_TYPE is `azure`, set this to your Azure webhook URL
AZURE_URL=
# If API_TYPE is `azure`, set an optional password for webhook responses
AZURE_PASS=
AZURE_PASS=
# Put ID of server to limit owner-only commands to
ADMIN_SERVER=

View File

@ -66,6 +66,7 @@ class Command {
static requires = [];
static slashAllowed = true;
static directAllowed = true;
static adminOnly = false;
}
export default Command;

View File

@ -8,6 +8,7 @@ class BroadcastCommand extends Command {
if (!owners.includes(this.author.id)) {
this.success = false;
resolve("Only the bot owner can broadcast messages!");
return;
}
const message = this.options.message ?? this.args.join(" ");
if (message?.trim()) {
@ -35,6 +36,7 @@ class BroadcastCommand extends Command {
}];
static description = "Broadcasts a playing message until the command is run again or the bot restarts";
static adminOnly = true;
}
export default BroadcastCommand;

View File

@ -38,6 +38,7 @@ class EvalCommand extends Command {
static description = "Executes JavaScript code";
static aliases = ["run"];
static arguments = ["[code]"];
static adminOnly = true;
}
export default EvalCommand;

View File

@ -42,6 +42,7 @@ class ExecCommand extends Command {
static description = "Executes a shell command";
static aliases = ["runcmd"];
static arguments = ["[command]"];
static adminOnly = true;
}
export default ExecCommand;

View File

@ -16,7 +16,7 @@ class ImageReloadCommand extends Command {
}
static description = "Attempts to reconnect to all available image processing servers";
static aliases = ["magickconnect", "magick"];
static adminOnly = true;
}
export default ImageReloadCommand;

View File

@ -33,6 +33,7 @@ class ReloadCommand extends Command {
static description = "Reloads a command";
static arguments = ["[command]"];
static adminOnly = true;
}
export default ReloadCommand;

View File

@ -16,6 +16,7 @@ class RestartCommand extends Command {
static description = "Restarts me";
static aliases = ["reboot"];
static adminOnly = true;
}
export default RestartCommand;

View File

@ -28,6 +28,7 @@ class SoundReloadCommand extends Command {
static description = "Attempts to reconnect to all available Lavalink nodes";
static aliases = ["lava", "lavalink", "lavaconnect", "soundconnect"];
static adminOnly = true;
}
export default SoundReloadCommand;

View File

@ -21,4 +21,5 @@ Here's an overview of the variables that are not necessarily required for the bo
- `METRICS`: The HTTP port to serve [Prometheus](https://prometheus.io/)-compatible metrics on.
- `API`: Set this to "none" if you want to process all images locally. Alternatively, set it to "ws" to use an image API server specified in the `image` block of `servers.json`, or "azure" to use the Azure Functions-based API.
- `AZURE_URL`: Your Azure webhook URL. Only applies if `API` is set to "azure".
- `AZURE_PASS`: An optional password used for Azure requests. Only applies if `API` is set to "azure".
- `AZURE_PASS`: An optional password used for Azure requests. Only applies if `API` is set to "azure".
- `ADMIN_SERVER`: A server to limit owner-only commands to.

View File

@ -36,17 +36,7 @@ export default async (client, cluster, worker, ipc, interaction) => {
flags: result.flags ?? (commandClass.success ? 0 : 64)
}));
} else if (typeof result === "object" && result.file) {
let fileSize = 8388119;
if (interaction.channel.guild) {
switch (interaction.channel.guild.premiumTier) {
case 2:
fileSize = 52428308;
break;
case 3:
fileSize = 104856616;
break;
}
}
const fileSize = 8388119;
if (result.file.length > fileSize) {
if (process.env.TEMPDIR && process.env.TEMPDIR !== "") {
await upload(client, ipc, result, interaction, true);

View File

@ -40,8 +40,7 @@ theme:
name: Switch to light mode
plugins:
- glightbox
- git-revision-date-localized:
enable_creation_date: true
- git-revision-date-localized
extra:
social:
- icon: fontawesome/brands/twitter

View File

@ -26,6 +26,8 @@ import { generateList, createPage } from "./utils/help.js";
// whether a broadcast is currently in effect
let broadcast = false;
const playingSuffix = !types.classic ? ` | @${this.bot.user.username} help` : "";
class Shard extends BaseClusterWorker {
constructor(bot) {
super(bot);
@ -54,7 +56,14 @@ class Shard extends BaseClusterWorker {
if (types.application) {
const commandArray = await update(this.bot, this.clusterID, this.workerID, this.ipc, soundStatus);
try {
await this.bot.bulkEditCommands(commandArray);
log("info", "Sending application command data to Discord...");
let cmdArray = commandArray.main;
if (process.env.ADMIN_SERVER && process.env.ADMIN_SERVER !== "") {
await this.bot.bulkEditGuildCommands(process.env.ADMIN_SERVER, commandArray.private);
} else {
cmdArray = [...commandArray.main, ...commandArray.private];
}
await this.bot.bulkEditCommands(cmdArray);
} catch (e) {
log("error", e);
log("error", "Failed to send command data to Discord, slash/message commands may be unavailable.");
@ -111,7 +120,7 @@ class Shard extends BaseClusterWorker {
this.ipc.register("playbroadcast", (message) => {
this.bot.editStatus("dnd", {
name: `${message} | @${this.bot.user.username} help`,
name: message + playingSuffix,
});
broadcast = true;
return this.ipc.broadcast("broadcastSuccess");
@ -119,7 +128,7 @@ class Shard extends BaseClusterWorker {
this.ipc.register("broadcastend", () => {
this.bot.editStatus("dnd", {
name: `${random(messages)} | @${this.bot.user.username} help`,
name: random(messages) + playingSuffix,
});
broadcast = false;
return this.ipc.broadcast("broadcastEnd");
@ -132,7 +141,7 @@ class Shard extends BaseClusterWorker {
if (broadcastMessage) {
broadcast = true;
this.bot.editStatus("dnd", {
name: `${broadcastMessage} | @${this.bot.user.username} help`,
name: broadcastMessage + playingSuffix,
});
}
@ -145,7 +154,7 @@ class Shard extends BaseClusterWorker {
activityChanger() {
if (!broadcast) {
this.bot.editStatus("dnd", {
name: `${random(messages)} | @${this.bot.user.username} help`,
name: random(messages) + playingSuffix,
});
}
setTimeout(this.activityChanger.bind(this), 900000);

View File

@ -43,6 +43,7 @@ export async function load(client, cluster, worker, ipc, command, soundStatus, s
flags: props.flags,
slashAllowed: props.slashAllowed,
directAllowed: props.directAllowed,
adminOnly: props.adminOnly,
type: 1
};
@ -84,6 +85,7 @@ export async function load(client, cluster, worker, ipc, command, soundStatus, s
export async function update() {
const commandArray = [];
const privateCommandArray = [];
const merged = new Map([...commands, ...messageCommands]);
for (const [name, command] of merged.entries()) {
let cmdInfo = info.get(name);
@ -97,18 +99,19 @@ export async function update() {
flags: cmd.flags,
slashAllowed: cmd.slashAllowed,
directAllowed: cmd.directAllowed,
adminOnly: cmd.adminOnly,
type: cmdInfo.type
};
info.set(name, cmdInfo);
}
if (cmdInfo?.type === 3) {
commandArray.push({
(cmdInfo.adminOnly ? privateCommandArray : commandArray).push({
name: name,
type: cmdInfo.type,
dm_permission: cmdInfo.directAllowed
});
} else if (cmdInfo?.slashAllowed) {
commandArray.push({
(cmdInfo.adminOnly ? privateCommandArray : commandArray).push({
name,
type: cmdInfo.type,
description: cmdInfo.description,
@ -117,5 +120,8 @@ export async function update() {
});
}
}
return commandArray;
return {
main: commandArray,
private: privateCommandArray
};
}