mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
Add bot owner commands for adding/removing servers and dashboard users
This commit is contained in:
parent
cd4b7a2f97
commit
5d13322439
8 changed files with 195 additions and 1 deletions
|
@ -0,0 +1,46 @@
|
|||
import { botControlCmd } from "../types";
|
||||
import { isOwnerPreFilter, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { ApiPermissions } from "@shared/apiPermissions";
|
||||
|
||||
export const AddDashboardUserCmd = botControlCmd({
|
||||
trigger: ["add_dashboard_user"],
|
||||
permission: null,
|
||||
config: {
|
||||
preFilters: [isOwnerPreFilter],
|
||||
},
|
||||
|
||||
signature: {
|
||||
guildId: ct.string(),
|
||||
users: ct.user({ rest: true }),
|
||||
},
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
|
||||
for (const user of args.users) {
|
||||
const existingAssignment = await pluginData.state.apiPermissionAssignments.getByGuildAndUserId(
|
||||
args.guildId,
|
||||
user.id,
|
||||
);
|
||||
if (existingAssignment) {
|
||||
continue;
|
||||
}
|
||||
|
||||
await pluginData.state.apiPermissionAssignments.addUser(args.guildId, user.id, [ApiPermissions.EditConfig]);
|
||||
}
|
||||
|
||||
const userNameList = args.users.map(
|
||||
user => `<@!${user.id}> (**${user.username}#${user.discriminator}**, \`${user.id}\`)`,
|
||||
);
|
||||
sendSuccessMessage(
|
||||
pluginData,
|
||||
msg.channel,
|
||||
`The following users were given dashboard access for **${guild.name}**:\n\n${userNameList}`,
|
||||
);
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue