2021-01-17 20:52:25 +02:00
|
|
|
import { ApiPermissions } from "@shared/apiPermissions";
|
2021-06-02 04:07:50 +02:00
|
|
|
import { TextChannel } from "discord.js";
|
2021-06-06 23:51:32 +02:00
|
|
|
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
|
|
|
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
|
|
|
import { isSnowflake } from "../../../utils";
|
|
|
|
import { botControlCmd } from "../types";
|
2020-10-10 14:21:59 +03:00
|
|
|
|
|
|
|
export const AllowServerCmd = botControlCmd({
|
|
|
|
trigger: ["allow_server", "allowserver", "add_server", "addserver"],
|
|
|
|
permission: null,
|
|
|
|
config: {
|
|
|
|
preFilters: [isOwnerPreFilter],
|
|
|
|
},
|
|
|
|
|
|
|
|
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) {
|
2021-06-02 04:07:50 +02:00
|
|
|
sendErrorMessage(pluginData, msg.channel as TextChannel, "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)) {
|
2021-06-02 04:07:50 +02:00
|
|
|
sendErrorMessage(pluginData, msg.channel as TextChannel, "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)) {
|
2021-06-02 04:07:50 +02:00
|
|
|
sendErrorMessage(pluginData, msg.channel as TextChannel, "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) {
|
|
|
|
await pluginData.state.apiPermissionAssignments.addUser(args.guildId, args.userId, [ApiPermissions.EditConfig]);
|
|
|
|
}
|
|
|
|
|
2021-06-02 04:07:50 +02:00
|
|
|
sendSuccessMessage(pluginData, msg.channel as TextChannel, "Server is now allowed to use Zeppelin!");
|
2020-10-10 14:21:59 +03:00
|
|
|
},
|
|
|
|
});
|