Added Permission interface + Tweaked addcrowduser
This commit is contained in:
parent
2e2d49fff1
commit
37e2631ded
@ -37,6 +37,11 @@ export class CommandCollection {
|
||||
}
|
||||
}
|
||||
|
||||
interface Permissions {
|
||||
users: string[];
|
||||
groups: string[];
|
||||
}
|
||||
|
||||
export class Command {
|
||||
name : string;
|
||||
description? : string;
|
||||
@ -45,7 +50,7 @@ export class Command {
|
||||
cooldown? : number;
|
||||
aliases? : string[];
|
||||
usage? : string;
|
||||
permissions? : string[];
|
||||
permissions? : Permissions;
|
||||
|
||||
constructor(
|
||||
name : string,
|
||||
@ -57,7 +62,7 @@ export class Command {
|
||||
cooldown = 0,
|
||||
aliases = null as string[],
|
||||
usage = null as string,
|
||||
permissions = null as string[],
|
||||
permissions = null as Permissions,
|
||||
}
|
||||
) {
|
||||
this.name = name.toLowerCase();
|
||||
@ -73,4 +78,17 @@ export class Command {
|
||||
checkName(commandName : string) {
|
||||
return commandName === this.name || (this.aliases && this.aliases.includes(commandName));
|
||||
}
|
||||
|
||||
checkPermission(userId : string) : boolean {
|
||||
if (!this.permissions) return true;
|
||||
|
||||
if (this.permissions.users.includes(userId))
|
||||
return true;
|
||||
|
||||
for (const group of this.permissions.groups)
|
||||
if (group.includes(userId))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1,17 +1,19 @@
|
||||
import {Command} from "../Command";
|
||||
import got from 'got';
|
||||
|
||||
const {userDict, crowd} = require("../config.json");
|
||||
const {userDict, crowd, groupDict} = require("../config.json");
|
||||
|
||||
const addcrowduser = new Command(
|
||||
'addcrowduser',
|
||||
async (message, args) => {
|
||||
const email = args[0];
|
||||
const firstNameLetter = args[1][0].toLowerCase();
|
||||
const lastName = args[2].toLowerCase();
|
||||
const firstName = args[1];
|
||||
const lastName = args.splice(2).join(' ');
|
||||
const firstNameLetter = firstName[0].toLowerCase();
|
||||
const lastNameLowercase = lastName.toLowerCase().replace(/\s/g, '');;
|
||||
|
||||
const username = firstNameLetter + lastName;
|
||||
const password = lastName + firstNameLetter;
|
||||
const username = firstNameLetter + lastNameLowercase;
|
||||
const password = lastNameLowercase + firstNameLetter;
|
||||
|
||||
try {
|
||||
await got.post("https://conjure.etsmtl.ca/crowd/rest/usermanagement/1/user", {
|
||||
@ -27,9 +29,9 @@ const addcrowduser = new Command(
|
||||
"value": password
|
||||
},
|
||||
"active": true,
|
||||
"email": args[0],
|
||||
"first-name": args[1],
|
||||
"last-name": args[2]
|
||||
"email": email,
|
||||
"first-name": firstName,
|
||||
"last-name": lastName
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
@ -62,7 +64,10 @@ const addcrowduser = new Command(
|
||||
message.channel.send(`Member added.\nUsername: ${username}\nPassword: ${password}`);
|
||||
}, {
|
||||
description: "Adds a member to Crowd.",
|
||||
permissions: [userDict.misabiko, userDict.massimo],
|
||||
permissions: {
|
||||
users: [],
|
||||
groups: [groupDict.admin]
|
||||
},
|
||||
args: ['email', 'first name', 'last name']
|
||||
}
|
||||
);
|
||||
|
||||
@ -2,7 +2,7 @@ import {Command} from "../Command";
|
||||
import { TextChannel } from "discord.js";
|
||||
import * as mysql from 'mysql';
|
||||
|
||||
const {userDict, channels, mysql: mysqlCreds} = require("../config.json");
|
||||
const {userDict, channels, mysql: mysqlCreds, groupDict} = require("../config.json");
|
||||
|
||||
const listdiscordusers = new Command(
|
||||
'listdiscordusers',
|
||||
@ -42,7 +42,10 @@ const listdiscordusers = new Command(
|
||||
}
|
||||
}, {
|
||||
description: "Lists discord missing from database.",
|
||||
permissions: [userDict.misabiko, userDict.massimo]
|
||||
permissions: {
|
||||
users: [],
|
||||
groups: [groupDict.admin]
|
||||
}
|
||||
}
|
||||
);
|
||||
export default listdiscordusers;
|
||||
@ -17,7 +17,10 @@ const reloadcommand = new Command(
|
||||
description: "Reloads either every, or a given command module.",
|
||||
aliases: ["reload"],
|
||||
usage: "[commandName]",
|
||||
permissions: [userDict.misabiko]
|
||||
permissions: {
|
||||
users: [userDict.misabiko],
|
||||
groups: []
|
||||
}
|
||||
}
|
||||
);
|
||||
export default reloadcommand;
|
||||
|
||||
@ -53,7 +53,7 @@ export class CustomClient extends Discord.Client {
|
||||
if (command.guildOnly && message.channel.type !== 'text')
|
||||
return message.reply(`You can only call the ${command} commmand on a server.`);
|
||||
|
||||
if (command.permissions && !command.permissions.includes(message.author.id))
|
||||
if (!command.checkPermission(message.author.id))
|
||||
return message.reply(`You don't have the permission for that command, ask <@${userDict.misabiko}> for help.`);
|
||||
|
||||
if (!this.cooldowns[command.name])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user