add embed pagination for the library
This commit is contained in:
parent
285e6796d0
commit
98a1956744
|
@ -10,6 +10,7 @@
|
|||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@devraelfreeze/discordjs-pagination": "^2.7.6",
|
||||
"discord.js": "^14.14.1",
|
||||
"sqlite3": "^5.1.7",
|
||||
"ts-node": "^10.9.2"
|
||||
|
|
106
src/bot.ts
106
src/bot.ts
|
@ -5,9 +5,12 @@ import {
|
|||
EmbedBuilder,
|
||||
Events,
|
||||
GatewayIntentBits,
|
||||
Message, PermissionsBitField, REST,
|
||||
Message,
|
||||
PermissionsBitField,
|
||||
REST,
|
||||
Routes,
|
||||
User
|
||||
User,
|
||||
APIUser
|
||||
} from 'discord.js';
|
||||
import * as sqlite3 from 'sqlite3';
|
||||
import config from "./config";
|
||||
|
@ -17,6 +20,7 @@ import Reset from "./commands/reset";
|
|||
import SetModRole from "./commands/setModRole";
|
||||
import SetIgnorePrefix from "./commands/setIgnorePrefix";
|
||||
import SetAutoEmbedMessages from "./commands/setAutoEmbedMessages";
|
||||
import { pagination, ButtonsTypes, ButtonsStyles } from "@devraelfreeze/discordjs-pagination";
|
||||
|
||||
export class Bot {
|
||||
private db: sqlite3.Database;
|
||||
|
@ -142,40 +146,106 @@ export class Bot {
|
|||
|
||||
public sendEmbed(msg: Message<boolean>|ChatInputCommandInteraction) {
|
||||
this.db.all(
|
||||
'SELECT * FROM library ORDER BY amount DESC LIMIT 9',
|
||||
'SELECT * FROM library ORDER BY amount DESC',
|
||||
async (err, rows) => {
|
||||
if (rows) {
|
||||
const icons = [
|
||||
':first_place: • ',
|
||||
':second_place: • ',
|
||||
':third_place: • ',
|
||||
':four: • ',
|
||||
':five: • ',
|
||||
':six: • ',
|
||||
':seven: • ',
|
||||
':eight: • ',
|
||||
':nine: • ',
|
||||
const emotes = [
|
||||
':zero:',
|
||||
':one:',
|
||||
':two:',
|
||||
':three:',
|
||||
':four:',
|
||||
':five:',
|
||||
':six:',
|
||||
':seven:',
|
||||
':eight:',
|
||||
':nine:',
|
||||
];
|
||||
const fields = [];
|
||||
|
||||
const words = [];
|
||||
for (let index in rows) {
|
||||
fields.push({
|
||||
name: icons[index] + rows[index]['word'],
|
||||
let icon = '';
|
||||
let intIndex = Number.parseInt(index) + 1;
|
||||
switch (intIndex) {
|
||||
case 1:
|
||||
icon = ':first_place:';
|
||||
break;
|
||||
case 2:
|
||||
icon = ':second_place:';
|
||||
break;
|
||||
case 3:
|
||||
icon = ':third_place:';
|
||||
break;
|
||||
default:
|
||||
const numbers = intIndex.toString().split('');
|
||||
for (let i = 0; i < numbers.length; i++) {
|
||||
icon += emotes[numbers[i]];
|
||||
}
|
||||
}
|
||||
|
||||
icon += ' • ';
|
||||
|
||||
words.push({
|
||||
name: icon + rows[index]['word'],
|
||||
value: rows[index]['amount'] + ' uses',
|
||||
inline: true,
|
||||
});
|
||||
}
|
||||
|
||||
let fields = [];
|
||||
let embeds = [];
|
||||
for (const word of words) {
|
||||
fields.push(word);
|
||||
|
||||
if (fields.length < 9) {
|
||||
continue;
|
||||
}
|
||||
|
||||
fields.push({
|
||||
name: '⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤',
|
||||
value: '\u200B',
|
||||
});
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('Top 9 most used words.')
|
||||
.setTitle(embeds.length > 0 ? 'Almighty Library' : 'Top 9 most used words.')
|
||||
.setDescription('This is the Library with the most used words and their amount.\u200B⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤')
|
||||
.setColor(0xffe600)
|
||||
.setFields(fields);
|
||||
await msg.reply({embeds: [embed]});
|
||||
|
||||
embeds.push(embed);
|
||||
fields = [];
|
||||
}
|
||||
|
||||
if (fields.length > 0) {
|
||||
fields.push({
|
||||
name: '⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤',
|
||||
value: '\u200B',
|
||||
});
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle('Almighty Library')
|
||||
.setDescription('This is the Library with the most used words and their amount.\u200B⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤⏤')
|
||||
.setColor(0xffe600)
|
||||
.setFields(fields);
|
||||
|
||||
embeds.push(embed);
|
||||
}
|
||||
|
||||
const user = msg.member.user;
|
||||
if (!(user instanceof User)) {
|
||||
console.log('devrael fucked up', user);
|
||||
return;
|
||||
}
|
||||
|
||||
await pagination({
|
||||
embeds: embeds,
|
||||
author: user,
|
||||
interaction: msg instanceof Message ? null : msg,
|
||||
message: msg instanceof Message ? msg : null,
|
||||
fastSkip: true,
|
||||
ephemeral: false,
|
||||
pageTravel: true,
|
||||
});
|
||||
|
||||
this.counter = 0;
|
||||
console.log('sendEmbed: sent library embed and set counter to 0');
|
||||
|
|
Loading…
Reference in New Issue