mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-07-07 11:20:59 +02:00
feat(arabot): add message command for temp ban
This commit is contained in:
parent
7421052f44
commit
b6bd3c6e80
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "arabot",
|
||||
"version": "0.2.3",
|
||||
"version": "0.2.4",
|
||||
"description": "A Discord bot for Animal Rights Advocates",
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
|
@ -17,7 +17,7 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Command, RegisterBehavior } from '@sapphire/framework';
|
||||
import { Args, Command, RegisterBehavior } from '@sapphire/framework';
|
||||
import { Duration, DurationFormatter } from '@sapphire/time-utilities';
|
||||
import type {
|
||||
User,
|
||||
@ -25,7 +25,7 @@ import type {
|
||||
TextChannel,
|
||||
Guild,
|
||||
} from 'discord.js';
|
||||
import { EmbedBuilder } from 'discord.js';
|
||||
import { EmbedBuilder, Message } from 'discord.js';
|
||||
import IDs from '#utils/ids';
|
||||
import { addTempBan, checkTempBan } from '#utils/database/tempBan';
|
||||
import { addEmptyUser, updateUser, userExists } from '#utils/database/dbExistingUser';
|
||||
@ -94,6 +94,96 @@ export class TempBanCommand extends Command {
|
||||
await interaction.reply({ content: ban.message });
|
||||
}
|
||||
|
||||
// Non Application Command method of banning a user
|
||||
public async messageRun(message: Message, args: Args) {
|
||||
// Get arguments
|
||||
let user: User;
|
||||
try {
|
||||
user = await args.pick('user');
|
||||
} catch {
|
||||
await message.react('❌');
|
||||
await message.reply('User was not provided!');
|
||||
return;
|
||||
}
|
||||
const arg = args.finished ? null : await args.rest('string');
|
||||
const mod = message.member;
|
||||
|
||||
if (arg === null) {
|
||||
await message.react('❌');
|
||||
await message.reply('Ban reason was not provided!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (mod === null) {
|
||||
await message.react('❌');
|
||||
await message.reply('Moderator not found! Try again or contact a developer!');
|
||||
return;
|
||||
}
|
||||
|
||||
const { duration, reason } = this.findTimeAndReason(arg);
|
||||
|
||||
if (Number.isNaN(duration.offset)) {
|
||||
await message.react('❌');
|
||||
await message.reply('Invalid time length for ban!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (reason.length === 0) {
|
||||
await message.react('❌');
|
||||
await message.reply('Reason was not provided!');
|
||||
return;
|
||||
}
|
||||
|
||||
const { guild } = message;
|
||||
|
||||
if (guild === null) {
|
||||
await message.react('❌');
|
||||
await message.reply('Guild not found! Try again or contact a developer!');
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.channel.id !== IDs.channels.restricted.moderators) {
|
||||
await message.react('❌');
|
||||
await message.reply(`You can only run this command in <#${IDs.channels.restricted.moderators}> `
|
||||
+ 'or alternatively use the slash command!');
|
||||
return;
|
||||
}
|
||||
|
||||
const ban = await this.ban(user.id, mod.user.id, duration, reason, guild);
|
||||
|
||||
await message.reply(ban.message);
|
||||
await message.react(ban.success ? '✅' : '❌');
|
||||
}
|
||||
|
||||
private findTimeAndReason(args: string) {
|
||||
const info = {
|
||||
duration: new Duration(''),
|
||||
reason: '',
|
||||
};
|
||||
|
||||
if (Number.isNaN(new Duration(args).offset)) {
|
||||
return info;
|
||||
}
|
||||
|
||||
const spliced = args.split(' ');
|
||||
let time = '';
|
||||
for (let i = 0; i < spliced.length; i += 1) {
|
||||
if (!Number.isNaN(new Duration(spliced[i]).offset)) {
|
||||
time += spliced[i];
|
||||
} else {
|
||||
info.reason = args.slice(args.indexOf(spliced[i]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (time.length === 0) {
|
||||
return info;
|
||||
}
|
||||
|
||||
info.duration = new Duration(time);
|
||||
return info;
|
||||
}
|
||||
|
||||
private async ban(
|
||||
userId: Snowflake,
|
||||
modId: Snowflake,
|
||||
|
Loading…
x
Reference in New Issue
Block a user