From 7316b62282dbf0cce852d1916f8570629e95603b Mon Sep 17 00:00:00 2001 From: Bsian Date: Thu, 21 Nov 2019 14:35:21 +0000 Subject: [PATCH] Added command --- src/commands/index.ts | 1 + src/commands/unban.ts | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/commands/unban.ts diff --git a/src/commands/index.ts b/src/commands/index.ts index 600c9de..ee72450 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -17,6 +17,7 @@ export { default as Pull } from './pull'; export { default as Restart } from './restart'; export { default as SecureSign } from './securesign'; export { default as Sysinfo } from './sysinfo'; +export { default as Unban } from './unban'; export { default as Unlock } from './unlock'; export { default as Warn } from './warn'; export { default as Whois } from './whois'; diff --git a/src/commands/unban.ts b/src/commands/unban.ts new file mode 100644 index 0000000..8366434 --- /dev/null +++ b/src/commands/unban.ts @@ -0,0 +1,35 @@ +import { Message } from 'eris'; +import { Client } from '..'; +import { Command } from '../class'; + +export default class Unban extends Command { + constructor(client: Client) { + super(client); + + this.name = 'unban'; + this.description = 'Unban an IP from Cloud/NGINX'; + this.aliases = ['unbanip']; + this.usage = `${this.client.config.prefix}unban [service] [ip]`; + this.permissions = { roles: ['455972169449734144', '643619219988152321'] }; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[1]) return this.client.commands.get('help').run(message, [this.name]); + const msg = await message.channel.createMessage(`${this.client.stores.emojis.loading} ***Unbanning IP...***`); + try { + await this.client.util.exec(`sudo fail2ban-client set ${args[0]} unbanip ${args[1]}`); + } catch (error) { + if (error.message.includes('is not banned')) return msg.edit(`${this.client.stores.emojis.error} ***IP address not banned***`); + if (error.message.includes(`'${args[0]}'`)) return msg.edit(`${this.client.stores.emojis.error} ***Invalid service***`); + throw error; + } + + message.delete(); + return msg.edit(`${this.client.stores.emojis.success} ***IP address ${args[1]} unbanned from ${args[0].toUpperCase()}***`); + } catch (error) { + return this.client.util.handleError(error, message, this); + } + } +}