3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-07-07 11:07:19 +00:00

Merge branch '240811_application_commands_merge_2' into next

This commit is contained in:
Dragory 2024-08-11 22:28:41 +03:00
commit 43b8017985
No known key found for this signature in database
279 changed files with 6192 additions and 3044 deletions

View file

@ -4,7 +4,6 @@ import { AllowedGuilds } from "../../data/AllowedGuilds.js";
import { ApiPermissionAssignments } from "../../data/ApiPermissionAssignments.js";
import { Configs } from "../../data/Configs.js";
import { GuildArchives } from "../../data/GuildArchives.js";
import { sendSuccessMessage } from "../../pluginUtils.js";
import { getActiveReload, resetActiveReload } from "./activeReload.js";
import { AddDashboardUserCmd } from "./commands/AddDashboardUserCmd.js";
import { AddServerFromInviteCmd } from "./commands/AddServerFromInviteCmd.js";
@ -77,7 +76,7 @@ export const BotControlPlugin = globalPlugin<BotControlPluginType>()({
if (guild) {
const channel = guild.channels.cache.get(channelId as Snowflake);
if (channel instanceof TextChannel) {
sendSuccessMessage(pluginData, channel, "Global plugins reloaded!");
void channel.send("Global plugins reloaded!");
}
}
}

View file

@ -1,6 +1,6 @@
import { ApiPermissions } from "@zeppelinbot/shared/apiPermissions.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { renderUsername } from "../../../utils.js";
import { botControlCmd } from "../types.js";
@ -19,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");
void msg.channel.send("Server is not using Zeppelin");
return;
}
@ -36,10 +36,7 @@ export const AddDashboardUserCmd = botControlCmd({
}
const userNameList = args.users.map((user) => `<@!${user.id}> (**${renderUsername(user)}**, \`${user.id}\`)`);
sendSuccessMessage(
pluginData,
msg.channel,
`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}`);
},
});

View file

@ -1,7 +1,6 @@
import { ApiPermissions } from "@zeppelinbot/shared/apiPermissions.js";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { DBDateFormat, isGuildInvite, resolveInvite } from "../../../utils.js";
import { isEligible } from "../functions/isEligible.js";
import { botControlCmd } from "../types.js";
@ -18,19 +17,19 @@ export const AddServerFromInviteCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
if (!invite || !isGuildInvite(invite)) {
sendErrorMessage(pluginData, msg.channel, "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) {
sendErrorMessage(pluginData, msg.channel, "Server is already allowed!");
void msg.channel.send("Server is already allowed!");
return;
}
const { result, explanation } = await isEligible(pluginData, args.user, invite);
if (!result) {
sendErrorMessage(pluginData, msg.channel, `Could not add server because it's not eligible: ${explanation}`);
msg.channel.send(`Could not add server because it's not eligible: ${explanation}`);
return;
}
@ -51,6 +50,6 @@ export const AddServerFromInviteCmd = botControlCmd({
);
}
sendSuccessMessage(pluginData, msg.channel, "Server was eligible and is now allowed to use Zeppelin!");
msg.channel.send("Server was eligible and is now allowed to use Zeppelin!");
},
});

View file

@ -1,7 +1,7 @@
import { ApiPermissions } from "@zeppelinbot/shared/apiPermissions.js";
import moment from "moment-timezone";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { DBDateFormat, isSnowflake } from "../../../utils.js";
import { botControlCmd } from "../types.js";
@ -20,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!");
void msg.channel.send("Server is already allowed!");
return;
}
if (!isSnowflake(args.guildId)) {
sendErrorMessage(pluginData, msg.channel, "Invalid server ID!");
void msg.channel.send("Invalid server ID!");
return;
}
if (args.userId && !isSnowflake(args.userId)) {
sendErrorMessage(pluginData, msg.channel, "Invalid user ID!");
void msg.channel.send("Invalid user ID!");
return;
}
@ -51,6 +51,6 @@ export const AllowServerCmd = botControlCmd({
);
}
sendSuccessMessage(pluginData, msg.channel, "Server is now allowed to use Zeppelin!");
void msg.channel.send("Server is now allowed to use Zeppelin!");
},
});

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { isStaffPreFilter, sendErrorMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { botControlCmd } from "../types.js";
export const ChannelToServerCmd = botControlCmd({
@ -16,7 +16,7 @@ export const ChannelToServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const channel = pluginData.client.channels.cache.get(args.channelId);
if (!channel) {
sendErrorMessage(pluginData, msg.channel, "Channel not found in cache!");
void msg.channel.send("Channel not found in cache!");
return;
}

View file

@ -1,6 +1,6 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { noop } from "../../../utils.js";
import { botControlCmd } from "../types.js";
@ -18,7 +18,7 @@ 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!");
void msg.channel.send("That server is not allowed in the first place!");
return;
}
@ -27,6 +27,6 @@ export const DisallowServerCmd = botControlCmd({
.get(args.guildId as Snowflake)
?.leave()
.catch(noop);
sendSuccessMessage(pluginData, msg.channel, "Server removed!");
void msg.channel.send("Server removed!");
},
});

View file

@ -1,5 +1,4 @@
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { isGuildInvite, resolveInvite } from "../../../utils.js";
import { isEligible } from "../functions/isEligible.js";
import { botControlCmd } from "../types.js";
@ -16,17 +15,17 @@ export const EligibleCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
const invite = await resolveInvite(pluginData.client, args.inviteCode, true);
if (!invite || !isGuildInvite(invite)) {
sendErrorMessage(pluginData, msg.channel, "Could not resolve invite");
void msg.channel.send("Could not resolve invite");
return;
}
const { result, explanation } = await isEligible(pluginData, args.user, invite);
if (result) {
sendSuccessMessage(pluginData, msg.channel, `Server is eligible: ${explanation}`);
void msg.channel.send(`Server is eligible: ${explanation}`);
return;
}
sendErrorMessage(pluginData, msg.channel, `Server is **NOT** eligible: ${explanation}`);
void msg.channel.send(`Server is **NOT** eligible: ${explanation}`);
},
});

View file

@ -1,6 +1,6 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { botControlCmd } from "../types.js";
export const LeaveServerCmd = botControlCmd({
@ -16,7 +16,7 @@ export const LeaveServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
sendErrorMessage(pluginData, msg.channel, "I am not in that guild");
void msg.channel.send("I am not in that guild");
return;
}
@ -26,10 +26,10 @@ export const LeaveServerCmd = botControlCmd({
try {
await pluginData.client.guilds.cache.get(args.guildId as Snowflake)?.leave();
} catch (e) {
sendErrorMessage(pluginData, msg.channel, `Failed to leave guild: ${e.message}`);
void msg.channel.send(`Failed to leave guild: ${e.message}`);
return;
}
sendSuccessMessage(pluginData, msg.channel, `Left guild **${guildName}**`);
void msg.channel.send(`Left guild **${guildName}**`);
},
});

View file

@ -1,7 +1,6 @@
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { AllowedGuild } from "../../../data/entities/AllowedGuild.js";
import { ApiPermissionAssignment } from "../../../data/entities/ApiPermissionAssignment.js";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { renderUsername, resolveUser } from "../../../utils.js";
import { botControlCmd } from "../types.js";
@ -16,7 +15,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.");
void msg.channel.send("Must specify at least guildId, user, or both.");
return;
}
@ -24,7 +23,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");
void msg.channel.send("Server is not using Zeppelin");
return;
}
}
@ -33,7 +32,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.");
void msg.channel.send("The user has no assigned permissions.");
return;
}
}
@ -54,11 +53,7 @@ export const ListDashboardPermsCmd = botControlCmd({
}
if (finalMessage === "") {
sendErrorMessage(
pluginData,
msg.channel,
`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
@ -67,7 +62,7 @@ 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.`);
msg.channel.send(`The server ${guildInfo} has no assigned permissions.`);
return;
}
@ -80,6 +75,9 @@ export const ListDashboardPermsCmd = botControlCmd({
}
}
await sendSuccessMessage(pluginData, msg.channel, finalMessage.trim(), {});
await msg.channel.send({
content: finalMessage.trim(),
allowedMentions: {},
});
},
});

View file

@ -1,5 +1,4 @@
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { renderUsername, resolveUser } from "../../../utils.js";
import { botControlCmd } from "../types.js";
@ -14,7 +13,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");
void msg.channel.send("Server is not using Zeppelin");
return;
}
@ -30,11 +29,9 @@ export const ListDashboardUsersCmd = botControlCmd({
`<@!${user.id}> (**${renderUsername(user)}**, \`${user.id}\`): ${permission.permissions.join(", ")}`,
);
sendSuccessMessage(
pluginData,
msg.channel,
`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: {},
});
},
});

View file

@ -1,6 +1,6 @@
import moment from "moment-timezone";
import { GuildArchives } from "../../../data/GuildArchives.js";
import { getBaseUrl, sendSuccessMessage } from "../../../pluginUtils.js";
import { getBaseUrl } from "../../../pluginUtils.js";
import { getRateLimitStats } from "../../../rateLimitStats.js";
import { botControlCmd } from "../types.js";
@ -13,7 +13,7 @@ export const RateLimitPerformanceCmd = botControlCmd({
async run({ pluginData, message: msg }) {
const logItems = getRateLimitStats();
if (logItems.length === 0) {
sendSuccessMessage(pluginData, msg.channel, `No rate limits hit`);
void msg.channel.send(`No rate limits hit`);
return;
}

View file

@ -1,4 +1,4 @@
import { isStaffPreFilter, sendErrorMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { getActiveReload, setActiveReload } from "../activeReload.js";
import { botControlCmd } from "../types.js";
@ -14,7 +14,7 @@ export const ReloadGlobalPluginsCmd = botControlCmd({
const guildId = "guild" in message.channel ? message.channel.guild.id : null;
if (!guildId) {
sendErrorMessage(pluginData, message.channel, "This command can only be used in a server");
void message.channel.send("This command can only be used in a server");
return;
}

View file

@ -1,6 +1,6 @@
import { Snowflake } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { botControlCmd } from "../types.js";
export const ReloadServerCmd = botControlCmd({
@ -16,18 +16,18 @@ export const ReloadServerCmd = botControlCmd({
async run({ pluginData, message: msg, args }) {
if (!pluginData.client.guilds.cache.has(args.guildId as Snowflake)) {
sendErrorMessage(pluginData, msg.channel, "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) {
sendErrorMessage(pluginData, msg.channel, `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);
sendSuccessMessage(pluginData, msg.channel, `Reloaded guild **${guild?.name || "???"}**`);
void msg.channel.send(`Reloaded guild **${guild?.name || "???"}**`);
},
});

View file

@ -1,5 +1,5 @@
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
import { isStaffPreFilter } from "../../../pluginUtils.js";
import { renderUsername } from "../../../utils.js";
import { botControlCmd } from "../types.js";
@ -18,7 +18,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");
void msg.channel.send("Server is not using Zeppelin");
return;
}
@ -35,10 +35,7 @@ export const RemoveDashboardUserCmd = botControlCmd({
}
const userNameList = args.users.map((user) => `<@!${user.id}> (**${renderUsername(user)}**, \`${user.id}\`)`);
sendSuccessMessage(
pluginData,
msg.channel,
`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}`);
},
});