mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-14 13:55:03 +00:00
Fixes, refactoring and PR feedback
This commit is contained in:
parent
0be54912c4
commit
893a77d562
202 changed files with 1037 additions and 1069 deletions
|
@ -4,7 +4,6 @@ import { AllowedGuilds } from "../../data/AllowedGuilds";
|
|||
import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments";
|
||||
import { Configs } from "../../data/Configs";
|
||||
import { GuildArchives } from "../../data/GuildArchives";
|
||||
import { CommonPlugin } from "../Common/CommonPlugin";
|
||||
import { getActiveReload, resetActiveReload } from "./activeReload";
|
||||
import { AddDashboardUserCmd } from "./commands/AddDashboardUserCmd";
|
||||
import { AddServerFromInviteCmd } from "./commands/AddServerFromInviteCmd";
|
||||
|
@ -77,7 +76,7 @@ export const BotControlPlugin = globalPlugin<BotControlPluginType>()({
|
|||
if (guild) {
|
||||
const channel = guild.channels.cache.get(channelId as Snowflake);
|
||||
if (channel instanceof TextChannel) {
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(channel, "Global plugins reloaded!");
|
||||
void channel.send("Global plugins reloaded!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ export const AddDashboardUserCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
|
||||
void msg.channel.send("Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,6 @@ export const AddDashboardUserCmd = botControlCmd({
|
|||
|
||||
const userNameList = args.users.map((user) => `<@!${user.id}> (**${renderUsername(user)}**, \`${user.id}\`)`);
|
||||
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendSuccessMessage(
|
||||
msg,
|
||||
`The following users were given dashboard access for **${guild.name}**:\n\n${userNameList}`,
|
||||
);
|
||||
msg.channel.send(`The following users were given dashboard access for **${guild.name}**:\n\n${userNameList}`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -18,21 +18,19 @@ export const AddServerFromInviteCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
|
||||
if (!invite || !isGuildInvite(invite)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Could not resolve invite"); // :D
|
||||
void msg.channel.send("Could not resolve invite"); // :D
|
||||
return;
|
||||
}
|
||||
|
||||
const existing = await pluginData.state.allowedGuilds.find(invite.guild.id);
|
||||
if (existing) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is already allowed!");
|
||||
void msg.channel.send("Server is already allowed!");
|
||||
return;
|
||||
}
|
||||
|
||||
const { result, explanation } = await isEligible(pluginData, args.user, invite);
|
||||
if (!result) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, `Could not add server because it's not eligible: ${explanation}`);
|
||||
msg.channel.send(`Could not add server because it's not eligible: ${explanation}`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -53,8 +51,6 @@ export const AddServerFromInviteCmd = botControlCmd({
|
|||
);
|
||||
}
|
||||
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendSuccessMessage(msg, "Server was eligible and is now allowed to use Zeppelin!");
|
||||
msg.channel.send("Server was eligible and is now allowed to use Zeppelin!");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -21,17 +21,17 @@ export const AllowServerCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const existing = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (existing) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is already allowed!");
|
||||
void msg.channel.send("Server is already allowed!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSnowflake(args.guildId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid server ID!");
|
||||
void msg.channel.send("Invalid server ID!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.userId && !isSnowflake(args.userId)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Invalid user ID!");
|
||||
void msg.channel.send("Invalid user ID!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -52,6 +52,6 @@ export const AllowServerCmd = botControlCmd({
|
|||
);
|
||||
}
|
||||
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Server is now allowed to use Zeppelin!");
|
||||
void msg.channel.send("Server is now allowed to use Zeppelin!");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ export const ChannelToServerCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const channel = pluginData.client.channels.cache.get(args.channelId);
|
||||
if (!channel) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Channel not found in cache!");
|
||||
void msg.channel.send("Channel not found in cache!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ export const DisallowServerCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const existing = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!existing) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "That server is not allowed in the first place!");
|
||||
void msg.channel.send("That server is not allowed in the first place!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -28,6 +28,6 @@ export const DisallowServerCmd = botControlCmd({
|
|||
.get(args.guildId as Snowflake)
|
||||
?.leave()
|
||||
.catch(noop);
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, "Server removed!");
|
||||
void msg.channel.send("Server removed!");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -16,17 +16,17 @@ export const EligibleCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
|
||||
if (!invite || !isGuildInvite(invite)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Could not resolve invite");
|
||||
void msg.channel.send("Could not resolve invite");
|
||||
return;
|
||||
}
|
||||
|
||||
const { result, explanation } = await isEligible(pluginData, args.user, invite);
|
||||
|
||||
if (result) {
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Server is eligible: ${explanation}`);
|
||||
void msg.channel.send(`Server is eligible: ${explanation}`);
|
||||
return;
|
||||
}
|
||||
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Server is **NOT** eligible: ${explanation}`);
|
||||
void msg.channel.send(`Server is **NOT** eligible: ${explanation}`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -17,7 +17,7 @@ export const LeaveServerCmd = botControlCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "I am not in that guild");
|
||||
void msg.channel.send("I am not in that guild");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,10 +27,10 @@ export const LeaveServerCmd = botControlCmd({
|
|||
try {
|
||||
await pluginData.client.guilds.cache.get(args.guildId as Snowflake)?.leave();
|
||||
} catch (e) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Failed to leave guild: ${e.message}`);
|
||||
void msg.channel.send(`Failed to leave guild: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Left guild **${guildName}**`);
|
||||
void msg.channel.send(`Left guild **${guildName}**`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
if (!args.user && !args.guildId) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Must specify at least guildId, user, or both.");
|
||||
void msg.channel.send("Must specify at least guildId, user, or both.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
if (args.guildId) {
|
||||
guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
|
||||
void msg.channel.send("Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
if (args.user) {
|
||||
existingUserAssignment = await pluginData.state.apiPermissionAssignments.getByUserId(args.user.id);
|
||||
if (existingUserAssignment.length === 0) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "The user has no assigned permissions.");
|
||||
void msg.channel.send("The user has no assigned permissions.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -54,9 +54,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
}
|
||||
|
||||
if (finalMessage === "") {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, `The user ${userInfo} has no assigned permissions on the specified server.`);
|
||||
msg.channel.send(`The user ${userInfo} has no assigned permissions on the specified server.`);
|
||||
return;
|
||||
}
|
||||
// Else display all users that have permissions on the specified guild
|
||||
|
@ -65,9 +63,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
|
||||
const existingGuildAssignment = await pluginData.state.apiPermissionAssignments.getByGuildId(guild.id);
|
||||
if (existingGuildAssignment.length === 0) {
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendErrorMessage(msg, `The server ${guildInfo} has no assigned permissions.`);
|
||||
msg.channel.send(`The server ${guildInfo} has no assigned permissions.`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -80,6 +76,9 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
}
|
||||
}
|
||||
|
||||
await pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, finalMessage.trim(), {});
|
||||
await msg.channel.send({
|
||||
content: finalMessage.trim(),
|
||||
allowedMentions: {},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ export const ListDashboardUsersCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
|
||||
void msg.channel.send("Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -30,12 +30,9 @@ export const ListDashboardUsersCmd = botControlCmd({
|
|||
`<@!${user.id}> (**${renderUsername(user)}**, \`${user.id}\`): ${permission.permissions.join(", ")}`,
|
||||
);
|
||||
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendSuccessMessage(
|
||||
msg,
|
||||
`The following users have dashboard access for **${guild.name}**:\n\n${userNameList.join("\n")}`,
|
||||
{},
|
||||
);
|
||||
msg.channel.send({
|
||||
content: `The following users have dashboard access for **${guild.name}**:\n\n${userNameList.join("\n")}`,
|
||||
allowedMentions: {},
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -14,7 +14,7 @@ export const RateLimitPerformanceCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg }) {
|
||||
const logItems = getRateLimitStats();
|
||||
if (logItems.length === 0) {
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `No rate limits hit`);
|
||||
void msg.channel.send(`No rate limits hit`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ export const ReloadGlobalPluginsCmd = botControlCmd({
|
|||
|
||||
const guildId = "guild" in message.channel ? message.channel.guild.id : null;
|
||||
if (!guildId) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(message, "This command can only be used in a server");
|
||||
void message.channel.send("This command can only be used in a server");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,18 +17,18 @@ export const ReloadServerCmd = botControlCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "I am not in that guild");
|
||||
void msg.channel.send("I am not in that guild");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await pluginData.getKnubInstance().reloadGuild(args.guildId);
|
||||
} catch (e) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, `Failed to reload guild: ${e.message}`);
|
||||
void msg.channel.send(`Failed to reload guild: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const guild = await pluginData.client.guilds.fetch(args.guildId as Snowflake);
|
||||
pluginData.getPlugin(CommonPlugin).sendSuccessMessage(msg, `Reloaded guild **${guild?.name || "???"}**`);
|
||||
void msg.channel.send(`Reloaded guild **${guild?.name || "???"}**`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
pluginData.getPlugin(CommonPlugin).sendErrorMessage(msg, "Server is not using Zeppelin");
|
||||
void msg.channel.send("Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,8 @@ export const RemoveDashboardUserCmd = botControlCmd({
|
|||
|
||||
const userNameList = args.users.map((user) => `<@!${user.id}> (**${renderUsername(user)}**, \`${user.id}\`)`);
|
||||
|
||||
pluginData
|
||||
.getPlugin(CommonPlugin)
|
||||
.sendSuccessMessage(
|
||||
msg,
|
||||
`The following users were removed from the dashboard for **${guild.name}**:\n\n${userNameList}`,
|
||||
);
|
||||
msg.channel.send(
|
||||
`The following users were removed from the dashboard for **${guild.name}**:\n\n${userNameList}`,
|
||||
);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { BasePluginType, globalPluginEventListener, globalPluginMessageCommand } from "knub";
|
||||
import { BasePluginType, globalPluginEventListener, globalPluginMessageCommand, pluginUtils } from "knub";
|
||||
import z from "zod";
|
||||
import { AllowedGuilds } from "../../data/AllowedGuilds";
|
||||
import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue