Skip to content

Commit

Permalink
Revert "fixes #60"
Browse files Browse the repository at this point in the history
This reverts commit 9e1d017.
  • Loading branch information
msawatzky75 committed Dec 12, 2023
1 parent 05afa9a commit b04f16d
Show file tree
Hide file tree
Showing 218 changed files with 1,157 additions and 2,722 deletions.
1,849 changes: 526 additions & 1,323 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/gopd-npm-1.0.1-10c1d0b534-a5ccfb8806.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/ws-npm-8.14.2-b339ac47a2-3ca0dad26e.zip
Binary file not shown.
Binary file removed .yarn/cache/ws-npm-8.15.0-6c613b28fb-ca15c590aa.zip
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
---

version: "3"

services:
Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@
"prettier": "prettier --write ."
},
"dependencies": {
"@discordjs/rest": "^1.7.1",
"@discordjs/rest": "^1.1.0",
"debug": "^4.3.4",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"typescript": "^4.9.5"
"discord.js": "^14.3.0",
"dotenv": "^16.0.2",
"typescript": "^4.8.2"
},
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/node": "^16.18.68",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"eslint": "^8.55.0",
"eslint-config-prettier": "^8.10.0",
"eslint-plugin-import": "^2.29.0",
"nodemon": "^2.0.22",
"prettier": "^2.8.8",
"rimraf": "^5.0.5"
"@types/debug": "^4.1.7",
"@types/node": "^16.11.7",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"eslint": "^8.23.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"nodemon": "^2.0.19",
"prettier": "^2.7.1",
"rimraf": "^3.0.2"
},
"packageManager": "[email protected]"
}
58 changes: 16 additions & 42 deletions src/commands/quote.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import debug from "debug";
import {
ChatInputCommandInteraction,
Collection,
Message,
SlashCommandBuilder,
Snowflake,
TextChannel,
} from "discord.js";
import {ChatInputCommandInteraction, Collection, Message, SlashCommandBuilder, TextChannel} from "discord.js";
import type {Command} from "./index";

const d = debug("bot.commands.quote");
const messages = new Collection<Snowflake, Collection<string, Message<true>>>();
const lastUpdate = new Collection<Snowflake, Date>();
const cacheLife = 1000 * 60 * 15; // 15 minutes

const command: Command = {
data: new SlashCommandBuilder()
Expand All @@ -28,19 +18,23 @@ const command: Command = {

if (!(quoteChannel instanceof TextChannel)) throw new Error("Could not find quote channel");

let serverMessages = messages.get(quoteChannel.guildId);
let timeSinceUpdate = new Date().getTime() - (lastUpdate.get(quoteChannel.guildId)?.getTime() ?? 0);
const limit = 100;

if (!serverMessages) {
d(`No cache for ${quoteChannel.guild.name}, fetching quotes...`);
await UpdateMessages(quoteChannel);
}
if (timeSinceUpdate >= cacheLife) {
d(`Cache expired for ${quoteChannel.guild.name}, fetching quotes...`);
await UpdateMessages(quoteChannel);
}
let messages: Collection<string, Message<true>> = new Collection();
let fetchedMessageCount = 0;
let pages = 0;

const randomMessage = messages.get(quoteChannel.guildId).random();
do {
d(`fetching ${limit} new messages...`);
const newMessages = await quoteChannel.messages.fetch({limit: limit, before: messages.last()?.id});
fetchedMessageCount = newMessages.size;
messages = messages.concat(newMessages);
pages++;
} while (fetchedMessageCount === limit);

d(`fetched ${messages.size} messages over ${pages} pages`);

const randomMessage = messages.random();

// replace mentions with their names
const content = randomMessage.content.replace(/<@!?(\d+)>/g, (match) => {
Expand All @@ -53,24 +47,4 @@ const command: Command = {
},
};

async function UpdateMessages(quoteChannel: TextChannel) {
const limit = 100;

let quoteMessages: Collection<string, Message<true>> = new Collection();
let fetchedMessageCount = 0;
let pages = 0;

do {
d(`fetching ${limit} new messages...`);
const newMessages = await quoteChannel.messages.fetch({limit: limit, before: quoteMessages.last()?.id});
fetchedMessageCount = newMessages.size;
quoteMessages = quoteMessages.concat(newMessages);
pages++;
} while (fetchedMessageCount === limit);

d(`fetched ${quoteMessages.size} messages over ${pages} pages`);
messages.set(quoteChannel.guildId, quoteMessages);
lastUpdate.set(quoteChannel.guildId, new Date());
}

export default command;
Loading

0 comments on commit b04f16d

Please sign in to comment.