Add warning command
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
import { Channel, GuildBasedChannel, GuildChannel, GuildTextBasedChannel, TextBasedChannel, VoiceBasedChannel } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
|
||||
export async function channelIsInStaffCategory(channel: GuildBasedChannel) {
|
||||
const staffCategories = await Database.getGuildStaffCategories(channel.guildId);
|
||||
|
||||
return staffCategories.includes(channel.parentId!);
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
export * from './array-utils';
|
||||
export * from './audit-log-utils';
|
||||
export * from './channel-utils';
|
||||
export * from './commands';
|
||||
export * from './e621-ticket-listener';
|
||||
export * from './e621-utils';
|
||||
@@ -8,4 +9,6 @@ export * from './message-utils';
|
||||
export * from './ms-to-human';
|
||||
export * from './refresh-commands';
|
||||
export * from './string-utils';
|
||||
export * from './ticket-utils';
|
||||
export * from './wait';
|
||||
export * from './warning-utils';
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import { ActionRowBuilder, APIEmbedField, ButtonBuilder, ButtonStyle, EmbedBuilder, GuildMember, MessageActionRowComponentBuilder, time } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
import { Warning } from '../types';
|
||||
|
||||
type MessageContent = { content: string, components: ActionRowBuilder<ButtonBuilder>[] };
|
||||
|
||||
const WARNINGS_PER_PAGE = 5;
|
||||
|
||||
function getWarningText(warning: Warning): string {
|
||||
const timestamp = time(new Date(warning.timestamp));
|
||||
|
||||
return `### Warning from <@${warning.mod_id}> (${timestamp}):\n${warning.reason}`;
|
||||
}
|
||||
|
||||
export async function getWarningMessage(userId: string, page: number): Promise<MessageContent | null> {
|
||||
const warnings = await Database.getWarnings(userId);
|
||||
|
||||
page = page - 1;
|
||||
|
||||
const maxPage = Math.floor(warnings.length / WARNINGS_PER_PAGE);
|
||||
|
||||
if (warnings.length == 0) return null;
|
||||
|
||||
const warningTexts: string[] = [];
|
||||
|
||||
for (let i = page * WARNINGS_PER_PAGE; i < page * WARNINGS_PER_PAGE + WARNINGS_PER_PAGE; i++) {
|
||||
if (i >= warnings.length) break;
|
||||
|
||||
warningTexts.push(getWarningText(warnings[i]));
|
||||
}
|
||||
|
||||
const prevPage = new ButtonBuilder()
|
||||
.setLabel('Previous Page')
|
||||
.setCustomId(`warning-previous_${userId}_${page + 1}`)
|
||||
.setDisabled(page == 0)
|
||||
.setStyle(ButtonStyle.Primary);
|
||||
|
||||
const nextPage = new ButtonBuilder()
|
||||
.setLabel('Next Page')
|
||||
.setCustomId(`warning-next_${userId}_${page + 1}`)
|
||||
.setDisabled(page >= maxPage)
|
||||
.setStyle(ButtonStyle.Primary);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(prevPage, nextPage);
|
||||
|
||||
return {
|
||||
content: `<@${userId}>'s Warnings\n` + warningTexts.join('\n\n') + `\n\n-# Page ${page + 1}/${maxPage + 1}`,
|
||||
components: [row]
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user