From 64a68e51a38eb89e98af65d9bac25e3f65c9bd47 Mon Sep 17 00:00:00 2001 From: Hiroyuki Date: Sat, 11 Sep 2021 16:38:35 -0400 Subject: [PATCH] feat: usermod command --- .eslintrc.json | 5 ++- src/class/AccountUtil.ts | 2 + src/class/Util.ts | 11 +---- src/commands/createaccount.ts | 3 +- src/commands/cwg_data.ts | 6 +-- src/commands/index.ts | 1 + src/commands/lock.ts | 2 +- src/commands/usermod.ts | 75 +++++++++++++++++++++++++++++++++++ 8 files changed, 89 insertions(+), 16 deletions(-) create mode 100644 src/commands/usermod.ts diff --git a/.eslintrc.json b/.eslintrc.json index af3e032..aac0c9e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -39,6 +39,7 @@ "import/prefer-default-export": "off", "no-useless-constructor": "off", "@typescript-eslint/no-useless-constructor": 2, - "import/extensions": "off" + "import/extensions": "off", + "consistent-return": "off" } -} \ No newline at end of file +} diff --git a/src/class/AccountUtil.ts b/src/class/AccountUtil.ts index d528e5b..7b2243c 100644 --- a/src/class/AccountUtil.ts +++ b/src/class/AccountUtil.ts @@ -4,6 +4,8 @@ import { randomBytes } from 'crypto'; import { AccountInterface } from '../models'; import { Client } from '..'; +export const LINUX_USERNAME_REGEX = /^[a-z][-a-z0-9]*$/; + export default class AccountUtil { public client: Client; diff --git a/src/class/Util.ts b/src/class/Util.ts index 5e9f2f2..d4e7ddb 100644 --- a/src/class/Util.ts +++ b/src/class/Util.ts @@ -311,16 +311,9 @@ export default class Util { return Promise.resolve(log); } - public getAcctHash(userpath: string) { - try { - return fs.readFileSync(`${userpath}/.securesign/auth`).toString(); - } catch (error) { - return null; - } - } - public parseCertificate(pem: string) { - return axios.post('https://certapi.libraryofcode.org/parse', pem); + return axios.post('https://certapi.libraryofcode.org/parse', pem) + .then((response) => response.data); } public upload(text: string, extension = 'txt') { diff --git a/src/commands/createaccount.ts b/src/commands/createaccount.ts index 91d5f25..40c1af7 100644 --- a/src/commands/createaccount.ts +++ b/src/commands/createaccount.ts @@ -1,5 +1,6 @@ import { GuildMember, Message } from 'discord.js'; import { Client, Command } from '../class'; +import { LINUX_USERNAME_REGEX } from '../class/AccountUtil'; export default class CreateAccount extends Command { constructor(client: Client) { @@ -32,7 +33,7 @@ export default class CreateAccount extends Command { if (checkAccount) return this.error(message.channel, 'Account already exists with this username.'); if (!this.client.util.isValidEmail(args[1])) return this.error(message.channel, 'Invalid email address supplied.'); - if (!/^[a-z][-a-z0-9]*$/.test(args[2])) return this.error(message.channel, 'Invalid username supplied.'); + if (!LINUX_USERNAME_REGEX.test(args[2])) return this.error(message.channel, 'Invalid username supplied.'); const confirmation = await this.loading(message.channel, 'Creating account...'); const data = await this.client.util.accounts.createAccount({ userID: args[0], username: args[2], emailAddress: args[1] }, message.author.id); diff --git a/src/commands/cwg_data.ts b/src/commands/cwg_data.ts index 5435d46..e0cca7f 100644 --- a/src/commands/cwg_data.ts +++ b/src/commands/cwg_data.ts @@ -37,9 +37,9 @@ export default class CWG_Data extends Command { embed.addField('Account ID', domain.account.userID, true); embed.addField('Domain', domain.domain, true); embed.addField('Port', String(domain.port), true); - embed.addField('Certificate Issuer', cert.data.issuer.organization[0], true); - embed.addField('Certificate Subject', cert.data.issuer.commonName, true); - embed.addField('Certificate Expiration Date', moment(cert.data.notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); + embed.addField('Certificate Issuer', cert.issuer.organization[0], true); + embed.addField('Certificate Subject', cert.issuer.commonName, true); + embed.addField('Certificate Expiration Date', moment(cert.notAfter).format('dddd, MMMM Do YYYY, h:mm:ss A'), true); embed.setFooter(this.client.user.username, this.client.user.avatarURL()); embed.setTimestamp(); return embed; diff --git a/src/commands/index.ts b/src/commands/index.ts index 85b7108..eaa87c7 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -28,6 +28,7 @@ export { default as systemd } from './systemd'; export { default as tier } from './tier'; export { default as unban } from './unban'; export { default as unlock } from './unlock'; +export { default as usermod } from './usermod'; export { default as users } from './users'; export { default as warn } from './warn'; export { default as whois } from './whois'; diff --git a/src/commands/lock.ts b/src/commands/lock.ts index f3a2df7..7f2a827 100644 --- a/src/commands/lock.ts +++ b/src/commands/lock.ts @@ -12,7 +12,7 @@ export default class Lock extends Command { this.usage = `${this.client.config.prefix}lock [User Name | User ID/Mention]