mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Finish preliminary rework, ready to test
This commit is contained in:
parent
57893e7f76
commit
d0a1beb809
177 changed files with 854 additions and 707 deletions
|
@ -2,6 +2,7 @@ import { botControlCmd } from "../types";
|
|||
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { ApiPermissions } from "@shared/apiPermissions";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const AddDashboardUserCmd = botControlCmd({
|
||||
trigger: ["add_dashboard_user"],
|
||||
|
@ -18,7 +19,7 @@ export const AddDashboardUserCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,7 @@ export const AddDashboardUserCmd = botControlCmd({
|
|||
);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
`The following users were given dashboard access for **${guild.name}**:\n\n${userNameList}`,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -3,6 +3,7 @@ import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../..
|
|||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { isSnowflake } from "../../../utils";
|
||||
import { ApiPermissions } from "@shared/apiPermissions";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const AllowServerCmd = botControlCmd({
|
||||
trigger: ["allow_server", "allowserver", "add_server", "addserver"],
|
||||
|
@ -19,17 +20,17 @@ export const AllowServerCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const existing = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (existing) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Server is already allowed!");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Server is already allowed!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isSnowflake(args.guildId)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid server ID!");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Invalid server ID!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.userId && !isSnowflake(args.userId)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Invalid user ID!");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Invalid user ID!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -40,6 +41,6 @@ export const AllowServerCmd = botControlCmd({
|
|||
await pluginData.state.apiPermissionAssignments.addUser(args.guildId, args.userId, [ApiPermissions.EditConfig]);
|
||||
}
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, "Server is now allowed to use Zeppelin!");
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, "Server is now allowed to use Zeppelin!");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ import { botControlCmd } from "../types";
|
|||
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { noop } from "../../../utils";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const DisallowServerCmd = botControlCmd({
|
||||
trigger: ["disallow_server", "disallowserver", "remove_server", "removeserver"],
|
||||
|
@ -17,12 +18,15 @@ export const DisallowServerCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const existing = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!existing) {
|
||||
sendErrorMessage(pluginData, msg.channel, "That server is not allowed in the first place!");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "That server is not allowed in the first place!");
|
||||
return;
|
||||
}
|
||||
|
||||
await pluginData.state.allowedGuilds.remove(args.guildId);
|
||||
await pluginData.client.leaveGuild(args.guildId).catch(noop);
|
||||
sendSuccessMessage(pluginData, msg.channel, "Server removed!");
|
||||
await pluginData.client.guilds.cache
|
||||
.get(args.guildId)
|
||||
?.leave()
|
||||
.catch(noop);
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, "Server removed!");
|
||||
},
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ import { botControlCmd } from "../types";
|
|||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { resolveInvite, verboseUserMention } from "../../../utils";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
const REQUIRED_MEMBER_COUNT = 5000;
|
||||
|
||||
|
@ -18,7 +19,7 @@ export const EligibleCmd = botControlCmd({
|
|||
if ((await pluginData.state.apiPermissionAssignments.getByUserId(args.user.id)).length) {
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
`${verboseUserMention(args.user)} is an existing bot operator. They are eligible!`,
|
||||
);
|
||||
return;
|
||||
|
@ -26,17 +27,17 @@ export const EligibleCmd = botControlCmd({
|
|||
|
||||
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
|
||||
if (!invite || !invite.guild) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Could not resolve server from invite");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Could not resolve server from invite");
|
||||
return;
|
||||
}
|
||||
|
||||
if (invite.guild.features.includes("PARTNERED")) {
|
||||
sendSuccessMessage(pluginData, msg.channel, `Server is partnered. It is eligible!`);
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Server is partnered. It is eligible!`);
|
||||
return;
|
||||
}
|
||||
|
||||
if (invite.guild.features.includes("VERIFIED")) {
|
||||
sendSuccessMessage(pluginData, msg.channel, `Server is verified. It is eligible!`);
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Server is verified. It is eligible!`);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -44,7 +45,7 @@ export const EligibleCmd = botControlCmd({
|
|||
if (memberCount >= REQUIRED_MEMBER_COUNT) {
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
`Server has ${memberCount} members, which is equal or higher than the required ${REQUIRED_MEMBER_COUNT}. It is eligible!`,
|
||||
);
|
||||
return;
|
||||
|
@ -52,7 +53,7 @@ export const EligibleCmd = botControlCmd({
|
|||
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
`Server **${invite.guild.name}** (\`${invite.guild.id}\`) is not eligible`,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { botControlCmd } from "../types";
|
||||
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const LeaveServerCmd = botControlCmd({
|
||||
trigger: ["leave_server", "leave_guild"],
|
||||
|
@ -14,21 +15,21 @@ export const LeaveServerCmd = botControlCmd({
|
|||
},
|
||||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
if (!pluginData.client.guilds.has(args.guildId)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "I am not in that guild");
|
||||
if (!pluginData.client.guilds.cache.has(args.guildId)) {
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "I am not in that guild");
|
||||
return;
|
||||
}
|
||||
|
||||
const guildToLeave = pluginData.client.guilds.get(args.guildId)!;
|
||||
const guildToLeave = await pluginData.client.guilds.fetch(args.guildId)!;
|
||||
const guildName = guildToLeave.name;
|
||||
|
||||
try {
|
||||
await pluginData.client.leaveGuild(args.guildId);
|
||||
await pluginData.client.guilds.cache.get(args.guildId)?.leave();
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Failed to leave guild: ${e.message}`);
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, `Failed to leave guild: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
sendSuccessMessage(pluginData, msg.channel, `Left guild **${guildName}**`);
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Left guild **${guildName}**`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -4,6 +4,7 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|||
import { createChunkedMessage, resolveUser } from "../../../utils";
|
||||
import { AllowedGuild } from "../../../data/entities/AllowedGuild";
|
||||
import { ApiPermissionAssignment } from "../../../data/entities/ApiPermissionAssignment";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const ListDashboardPermsCmd = botControlCmd({
|
||||
trigger: ["list_dashboard_permissions", "list_dashboard_perms", "list_dash_permissionss", "list_dash_perms"],
|
||||
|
@ -19,7 +20,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
if (!args.user && !args.guildId) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Must specify at least guildId, user, or both.");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Must specify at least guildId, user, or both.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -27,7 +28,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
if (args.guildId) {
|
||||
guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +37,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
if (args.user) {
|
||||
existingUserAssignment = await pluginData.state.apiPermissionAssignments.getByUserId(args.user.id);
|
||||
if (existingUserAssignment.length === 0) {
|
||||
sendErrorMessage(pluginData, msg.channel, "The user has no assigned permissions.");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "The user has no assigned permissions.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +60,7 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
if (finalMessage === "") {
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
`The user ${userInfo} has no assigned permissions on the specified server.`,
|
||||
);
|
||||
return;
|
||||
|
@ -70,7 +71,11 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
|
||||
const existingGuildAssignment = await pluginData.state.apiPermissionAssignments.getByGuildId(guild.id);
|
||||
if (existingGuildAssignment.length === 0) {
|
||||
sendErrorMessage(pluginData, msg.channel, `The server ${guildInfo} has no assigned permissions.`);
|
||||
sendErrorMessage(
|
||||
pluginData,
|
||||
msg.channel as TextChannel,
|
||||
`The server ${guildInfo} has no assigned permissions.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -83,6 +88,6 @@ export const ListDashboardPermsCmd = botControlCmd({
|
|||
}
|
||||
}
|
||||
|
||||
await sendSuccessMessage(pluginData, msg.channel, finalMessage.trim(), {});
|
||||
await sendSuccessMessage(pluginData, msg.channel as TextChannel, finalMessage.trim(), {});
|
||||
},
|
||||
});
|
||||
|
|
|
@ -3,6 +3,7 @@ import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../..
|
|||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { ApiPermissions } from "@shared/apiPermissions";
|
||||
import { resolveUser, UnknownUser } from "../../../utils";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const ListDashboardUsersCmd = botControlCmd({
|
||||
trigger: ["list_dashboard_users"],
|
||||
|
@ -18,7 +19,7 @@ export const ListDashboardUsersCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -30,7 +31,7 @@ export const ListDashboardUsersCmd = botControlCmd({
|
|||
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
`The following users have dashboard access for **${guild.name}**:\n\n${userNameList}`,
|
||||
{},
|
||||
);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { botControlCmd } from "../types";
|
||||
import { isOwnerPreFilter } from "../../../pluginUtils";
|
||||
import { getActiveReload, setActiveReload } from "../activeReload";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const ReloadGlobalPluginsCmd = botControlCmd({
|
||||
trigger: "bot_reload_global_plugins",
|
||||
|
@ -13,7 +14,7 @@ export const ReloadGlobalPluginsCmd = botControlCmd({
|
|||
if (getActiveReload()) return;
|
||||
|
||||
setActiveReload((message.channel as TextChannel).guild?.id, message.channel.id);
|
||||
await message.channel.createMessage("Reloading global plugins...");
|
||||
await message.channel.send("Reloading global plugins...");
|
||||
|
||||
pluginData.getKnubInstance().reloadGlobalContext();
|
||||
},
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import { botControlCmd } from "../types";
|
||||
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const ReloadServerCmd = botControlCmd({
|
||||
trigger: ["reload_server", "reload_guild"],
|
||||
|
@ -14,19 +15,19 @@ export const ReloadServerCmd = botControlCmd({
|
|||
},
|
||||
|
||||
async run({ pluginData, message: msg, args }) {
|
||||
if (!pluginData.client.guilds.has(args.guildId)) {
|
||||
sendErrorMessage(pluginData, msg.channel, "I am not in that guild");
|
||||
if (!pluginData.client.guilds.cache.has(args.guildId)) {
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "I am not in that guild");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await pluginData.getKnubInstance().reloadGuild(args.guildId);
|
||||
} catch (e) {
|
||||
sendErrorMessage(pluginData, msg.channel, `Failed to reload guild: ${e.message}`);
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, `Failed to reload guild: ${e.message}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const guild = pluginData.client.guilds.get(args.guildId);
|
||||
sendSuccessMessage(pluginData, msg.channel, `Reloaded guild **${guild?.name || "???"}**`);
|
||||
const guild = await pluginData.client.guilds.fetch(args.guildId);
|
||||
sendSuccessMessage(pluginData, msg.channel as TextChannel, `Reloaded guild **${guild?.name || "???"}**`);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -2,6 +2,7 @@ import { botControlCmd } from "../types";
|
|||
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { ApiPermissions } from "@shared/apiPermissions";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const RemoveDashboardUserCmd = botControlCmd({
|
||||
trigger: ["remove_dashboard_user"],
|
||||
|
@ -18,7 +19,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
|
|||
async run({ pluginData, message: msg, args }) {
|
||||
const guild = await pluginData.state.allowedGuilds.find(args.guildId);
|
||||
if (!guild) {
|
||||
sendErrorMessage(pluginData, msg.channel, "Server is not using Zeppelin");
|
||||
sendErrorMessage(pluginData, msg.channel as TextChannel, "Server is not using Zeppelin");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -39,7 +40,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
|
|||
);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
msg.channel as TextChannel,
|
||||
`The following users were removed from the dashboard for **${guild.name}**:\n\n${userNameList}`,
|
||||
);
|
||||
},
|
||||
|
|
|
@ -3,6 +3,7 @@ import { isOwnerPreFilter } from "../../../pluginUtils";
|
|||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import escapeStringRegexp from "escape-string-regexp";
|
||||
import { createChunkedMessage, getUser, sorter } from "../../../utils";
|
||||
import { TextChannel } from "discord.js";
|
||||
|
||||
export const ServersCmd = botControlCmd({
|
||||
trigger: ["servers", "guilds"],
|
||||
|
@ -23,7 +24,7 @@ export const ServersCmd = botControlCmd({
|
|||
const showList = Boolean(args.all || args.initialized || args.uninitialized || args.search);
|
||||
const search = args.search ? new RegExp([...args.search].map(s => escapeStringRegexp(s)).join(".*"), "i") : null;
|
||||
|
||||
const joinedGuilds = Array.from(pluginData.client.guilds.values());
|
||||
const joinedGuilds = Array.from(pluginData.client.guilds.cache.values());
|
||||
const loadedGuilds = pluginData.getKnubInstance().getLoadedGuilds();
|
||||
const loadedGuildsMap = loadedGuilds.reduce((map, guildData) => map.set(guildData.guildId, guildData), new Map());
|
||||
|
||||
|
@ -50,16 +51,16 @@ export const ServersCmd = botControlCmd({
|
|||
const owner = getUser(pluginData.client, g.ownerID);
|
||||
return `\`${paddedId}\` **${g.name}** (${g.memberCount} members) (owner **${owner.username}#${owner.discriminator}** \`${owner.id}\`)`;
|
||||
});
|
||||
createChunkedMessage(msg.channel, lines.join("\n"));
|
||||
createChunkedMessage(msg.channel as TextChannel, lines.join("\n"));
|
||||
} else {
|
||||
msg.channel.createMessage("No servers matched the filters");
|
||||
msg.channel.send("No servers matched the filters");
|
||||
}
|
||||
} else {
|
||||
const total = joinedGuilds.length;
|
||||
const initialized = joinedGuilds.filter(g => loadedGuildsMap.has(g.id)).length;
|
||||
const unInitialized = total - initialized;
|
||||
|
||||
msg.channel.createMessage(
|
||||
msg.channel.send(
|
||||
`I am on **${total} total servers**, of which **${initialized} are initialized** and **${unInitialized} are not initialized**`,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue