aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moderation/ban.ts
blob: be7a51f7777a5fa5066124f3d54a1c1de376a858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import { BushCommand, BushMessage, BushSlashMessage } from '@lib';
import { User } from 'discord.js';

export default class BanCommand extends BushCommand {
	public constructor() {
		super('ban', {
			aliases: ['ban'],
			category: 'moderation',
			args: [
				{
					id: 'user',
					type: 'user',
					prompt: {
						start: 'What user would you like to ban?',
						retry: '{error} Choose a valid user to ban.'
					}
				},
				{
					id: 'reason',
					type: 'contentWithDuration',
					match: 'restContent',
					prompt: {
						start: 'Why would you like to ban this user?',
						retry: '{error} Choose a ban reason.',
						optional: true
					}
				}
			],
			clientPermissions: ['BAN_MEMBERS'],
			userPermissions: ['BAN_MEMBERS'],
			description: {
				content: 'Ban a member from the server.',
				usage: 'ban <member> <reason> [--time]',
				examples: ['ban @user bad --time 69d']
			},
			slashOptions: [
				{
					type: 'USER',
					name: 'user',
					description: 'Who would you like to ban?',
					required: true
				},
				{
					type: 'STRING',
					name: 'reason',
					description: 'Why are they getting banned?',
					required: false
				}
			],
			slash: true
		});
	}
	// async *genResponses(
	// 	message: Message | CommandInteraction,
	// 	user: User,
	// 	reason?: string,
	// 	time?: number
	// ): AsyncIterable<string> {
	// 	const duration = moment.duration();
	// 	let modLogEntry: ModLog;
	// 	let banEntry: Ban;
	// 	// const translatedTime: string[] = [];
	// 	// Create guild entry so postgres doesn't get mad when I try and add a modlog entry
	// 	await Guild.findOrCreate({
	// 		where: {
	// 			id: message.guild.id
	// 		},
	// 		defaults: {
	// 			id: message.guild.id
	// 		}
	// 	});
	// 	try {
	// 		if (time) {
	// 			duration.add(time);
	// 			/* 	const parsed = [...time.matchAll(durationRegex)];
	// 				if (parsed.length < 1) {
	// 					yield `${this.client.util.emojis.error} Invalid time.`;
	// 					return;
	// 				}
	// 				for (const part of parsed) {
	// 					const translated = Object.keys(durationAliases).find((k) => durationAliases[k].includes(part[2]));
	// 					translatedTime.push(part[1] + ' ' + translated);
	// 					duration.add(Number(part[1]), translated as 'weeks' | 'days' | 'hours' | 'months' | 'minutes');
	// 				} */
	// 			modLogEntry = ModLog.build({
	// 				user: user.id,
	// 				guild: message.guild.id,
	// 				reason,
	// 				type: ModLogType.TEMP_BAN,
	// 				duration: duration.asMilliseconds(),
	// 				moderator: message instanceof CommandInteraction ? message.user.id : message.author.id
	// 			});
	// 			banEntry = Ban.build({
	// 				user: user.id,
	// 				guild: message.guild.id,
	// 				reason,
	// 				expires: new Date(new Date().getTime() + duration.asMilliseconds()),
	// 				modlog: modLogEntry.id
	// 			});
	// 		} else {
	// 			modLogEntry = ModLog.build({
	// 				user: user.id,
	// 				guild: message.guild.id,
	// 				reason,
	// 				type: ModLogType.BAN,
	// 				moderator: message instanceof CommandInteraction ? message.user.id : message.author.id
	// 			});
	// 			banEntry = Ban.build({
	// 				user: user.id,
	// 				guild: message.guild.id,
	// 				reason,
	// 				modlog: modLogEntry.id
	// 			});
	// 		}
	// 		await modLogEntry.save();
	// 		await banEntry.save();

	// 		try {
	// 			await user.send(
	// 				`You were banned in ${message.guild.name} ${duration ? duration.humanize() : 'permanently'} with reason \`${
	// 					reason || 'No reason given'
	// 				}\``
	// 			);
	// 		} catch {
	// 			yield `${this.client.util.emojis.warn} Unable to dm user`;
	// 		}
	// 		await message.guild.members.ban(user, {
	// 			reason: `Banned by ${message instanceof CommandInteraction ? message.user.tag : message.author.tag} with ${
	// 				reason ? `reason ${reason}` : 'no reason'
	// 			}`
	// 		});
	// 		yield `${this.client.util.emojis.success} Banned <@!${user.id}> ${
	// 			duration ? duration.humanize() : 'permanently'
	// 		} with reason \`${reason || 'No reason given'}\``;
	// 	} catch {
	// 		yield `${this.client.util.emojis.error} Error banning :/`;
	// 		await banEntry.destroy();
	// 		await modLogEntry.destroy();
	// 		return;
	// 	}
	// }
	async exec(
		message: BushMessage | BushSlashMessage,
		{ user, reason, time }: { user: User; reason?: string; time?: number | string }
	): Promise<unknown> {
		return message.util.reply(`${this.client.util.emojis.error} This command is not finished.`);

		// if (typeof time === 'string') {
		// 	time = (await Argument.cast('duration', this.client.commandHandler.resolver, message, time)) as number;
		// 	//// time = this.client.commandHandler.resolver.type('duration')
		// }
		// for await (const response of this.genResponses(message, user, reason, time)) {
		// 	await message.util.send(response);
		// }
	}
}