mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-09-19 18:22:20 +02:00
feat(arabot): add message command for temp ban
This commit is contained in:
parent
d681d7c183
commit
5fb9ae39a0
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "arabot",
|
"name": "arabot",
|
||||||
"version": "0.2.3",
|
"version": "0.2.4",
|
||||||
"description": "A Discord bot for Animal Rights Advocates",
|
"description": "A Discord bot for Animal Rights Advocates",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
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 { Duration, DurationFormatter } from '@sapphire/time-utilities';
|
||||||
import type {
|
import type {
|
||||||
User,
|
User,
|
||||||
@ -25,7 +25,7 @@ import type {
|
|||||||
TextChannel,
|
TextChannel,
|
||||||
Guild,
|
Guild,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
import { EmbedBuilder } from 'discord.js';
|
import { EmbedBuilder, Message } from 'discord.js';
|
||||||
import IDs from '#utils/ids';
|
import IDs from '#utils/ids';
|
||||||
import { addTempBan, checkTempBan } from '#utils/database/tempBan';
|
import { addTempBan, checkTempBan } from '#utils/database/tempBan';
|
||||||
import { addEmptyUser, updateUser, userExists } from '#utils/database/dbExistingUser';
|
import { addEmptyUser, updateUser, userExists } from '#utils/database/dbExistingUser';
|
||||||
@ -94,6 +94,96 @@ export class TempBanCommand extends Command {
|
|||||||
await interaction.reply({ content: ban.message });
|
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(
|
private async ban(
|
||||||
userId: Snowflake,
|
userId: Snowflake,
|
||||||
modId: Snowflake,
|
modId: Snowflake,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user