Rename warnings to notes

This commit is contained in:
Tarrgon
2025-05-29 10:34:11 -04:00
parent b5e631a965
commit 41299da489
8 changed files with 97 additions and 98 deletions
+1 -1
View File
@@ -11,5 +11,5 @@ export * from './refresh-commands';
export * from './string-utils';
export * from './ticket-utils';
export * from './wait';
export * from './warning-utils';
export * from './note-utils';
export * from './whois';
+51
View File
@@ -0,0 +1,51 @@
import { ActionRowBuilder, APIEmbedField, ButtonBuilder, ButtonStyle, EmbedBuilder, GuildMember, MessageActionRowComponentBuilder, time } from 'discord.js';
import { Database } from '../shared/Database';
import { Note } from '../types';
type MessageContent = { content: string, components: ActionRowBuilder<ButtonBuilder>[] };
const NOTES_PER_PAGE = 5;
function getNoteText(note: Note): string {
const timestamp = time(new Date(note.timestamp));
return `### Note by <@${note.mod_id}> (${timestamp}):\n${note.reason}`;
}
export async function getNoteMessage(userId: string, page: number): Promise<MessageContent | null> {
const notes = await Database.getNotes(userId);
page = page - 1;
const maxPage = Math.floor(notes.length / NOTES_PER_PAGE);
if (notes.length == 0) return null;
const noteTexts: string[] = [];
for (let i = page * NOTES_PER_PAGE; i < page * NOTES_PER_PAGE + NOTES_PER_PAGE; i++) {
if (i >= notes.length) break;
noteTexts.push(getNoteText(notes[i]));
}
const prevPage = new ButtonBuilder()
.setLabel('Previous Page')
.setCustomId(`note-previous_${userId}_${page + 1}`)
.setDisabled(page == 0)
.setStyle(ButtonStyle.Primary);
const nextPage = new ButtonBuilder()
.setLabel('Next Page')
.setCustomId(`note-next_${userId}_${page + 1}`)
.setDisabled(page >= maxPage)
.setStyle(ButtonStyle.Primary);
const row = new ActionRowBuilder<ButtonBuilder>()
.addComponents(prevPage, nextPage);
return {
content: `<@${userId}>'s Notes\n` + noteTexts.join('\n\n') + `\n\n-# Page ${page + 1}/${maxPage + 1}`,
components: [row]
};
}
-51
View File
@@ -1,51 +0,0 @@
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]
};
}