2024-03-02 09:24:07 +00:00
|
|
|
import { ApiPermissions } from "@zeppelinbot/shared";
|
2023-04-01 12:58:17 +01:00
|
|
|
import moment from "moment-timezone";
|
2024-04-09 20:57:18 +03:00
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes.js";
|
|
|
|
import { isStaffPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils.js";
|
|
|
|
import { DBDateFormat, isSnowflake } from "../../../utils.js";
|
|
|
|
import { botControlCmd } from "../types.js";
|
2020-10-10 14:21:59 +03:00
|
|
|
|
|
|
|
export const AllowServerCmd = botControlCmd({
|
|
|
|
trigger: ["allow_server", "allowserver", "add_server", "addserver"],
|
|
|
|
permission: null,
|
|
|
|
config: {
|
2022-08-06 21:31:13 +03:00
|
|
|
preFilters: [isStaffPreFilter],
|
2020-10-10 14:21:59 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
signature: {
|
|
|
|
guildId: ct.string(),
|
2021-01-17 20:52:25 +02:00
|
|
|
userId: ct.string({ required: false }),
|
2020-10-10 14:21:59 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
async run({ pluginData, message: msg, args }) {
|
|
|
|
const existing = await pluginData.state.allowedGuilds.find(args.guildId);
|
|
|
|
if (existing) {
|
2023-04-01 12:58:17 +01:00
|
|
|
sendErrorMessage(pluginData, msg.channel, "Server is already allowed!");
|
2020-10-10 14:21:59 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-10 15:29:23 +03:00
|
|
|
if (!isSnowflake(args.guildId)) {
|
2023-04-01 12:58:17 +01:00
|
|
|
sendErrorMessage(pluginData, msg.channel, "Invalid server ID!");
|
2020-10-10 15:29:23 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-17 20:52:25 +02:00
|
|
|
if (args.userId && !isSnowflake(args.userId)) {
|
2023-04-01 12:58:17 +01:00
|
|
|
sendErrorMessage(pluginData, msg.channel, "Invalid user ID!");
|
2021-01-17 20:52:25 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-10 14:21:59 +03:00
|
|
|
await pluginData.state.allowedGuilds.add(args.guildId);
|
2020-10-10 15:29:23 +03:00
|
|
|
await pluginData.state.configs.saveNewRevision(`guild-${args.guildId}`, "plugins: {}", msg.author.id);
|
2021-01-17 20:52:25 +02:00
|
|
|
|
|
|
|
if (args.userId) {
|
2021-09-05 17:07:50 +03:00
|
|
|
await pluginData.state.apiPermissionAssignments.addUser(args.guildId, args.userId, [ApiPermissions.ManageAccess]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.userId !== msg.author.id) {
|
|
|
|
// Add temporary access to user who added server
|
|
|
|
await pluginData.state.apiPermissionAssignments.addUser(
|
|
|
|
args.guildId,
|
|
|
|
msg.author.id,
|
|
|
|
[ApiPermissions.ManageAccess],
|
2021-09-11 19:06:51 +03:00
|
|
|
moment.utc().add(1, "hour").format(DBDateFormat),
|
2021-09-05 17:07:50 +03:00
|
|
|
);
|
2021-01-17 20:52:25 +02:00
|
|
|
}
|
|
|
|
|
2023-04-01 12:58:17 +01:00
|
|
|
sendSuccessMessage(pluginData, msg.channel, "Server is now allowed to use Zeppelin!");
|
2020-10-10 14:21:59 +03:00
|
|
|
},
|
|
|
|
});
|