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