mirror of
https://github.com/nx-bat/discordbot-ng.git
synced 2026-09-22 10:29:10 -04:00
Fix line endings
This commit is contained in:
+48
-48
@@ -1,49 +1,49 @@
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, time } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
import { MessageContent, Note } from '../types';
|
||||
|
||||
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)).sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
||||
|
||||
page = page - 1;
|
||||
|
||||
const maxPage = Math.max(0, Math.ceil(notes.length / NOTES_PER_PAGE) - 1);
|
||||
|
||||
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]
|
||||
};
|
||||
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, time } from 'discord.js';
|
||||
import { Database } from '../shared/Database';
|
||||
import { MessageContent, Note } from '../types';
|
||||
|
||||
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)).sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
||||
|
||||
page = page - 1;
|
||||
|
||||
const maxPage = Math.max(0, Math.ceil(notes.length / NOTES_PER_PAGE) - 1);
|
||||
|
||||
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]
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user