Skip to content

Commit

Permalink
fix srp
Browse files Browse the repository at this point in the history
Signed-off-by: RedGuy12 <paul@reid-family.org>
  • Loading branch information
cobaltt7 committed Aug 27, 2023
1 parent e73aaf3 commit d4bb9e2
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
49 changes: 31 additions & 18 deletions modules/board/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MessageType,
type Snowflake,
type TextBasedChannel,
BaseChannel,
} from "discord.js";
import config from "../../common/config.js";
import Database from "../../common/database.js";
Expand All @@ -30,44 +31,56 @@ export const boardDatabase = new Database<{
}>("board");
await boardDatabase.init();

const COUNTS = { scradd: 2, admins: 2, mods: 3, misc: 4, default: 6, memes: 8, info: 12 };
/**
* Determines the board reaction count for a channel.
*
* @param channel - The channel to determine reaction count for.
*
* @returns The reaction count.
*/
export function boardReactionCount(channel?: TextBasedChannel): number {
const COUNTS = { scradd: 2, admins: 2, mods: 3, misc: 4, default: 6, memes: 8, info: 12 };

export function boardReactionCount(channel?: TextBasedChannel): number;
export function boardReactionCount(channel: { id: Snowflake }): number | undefined;
export function boardReactionCount(channel?: TextBasedChannel | { id: Snowflake }) {
if (process.env.NODE_ENV !== "production") return COUNTS.scradd;
if (!channel) return COUNTS.default;

if (channel.id === config.channels.updates?.id) return COUNTS.info;

if (channel?.id === config.channels.updates?.id) return COUNTS.info;
const baseCount = baseReactionCount(channel.id);
if (!(channel instanceof BaseChannel)) return baseCount;

if (!channel.isTextBased()) return COUNTS.misc;
const baseChannel = getBaseChannel(channel);
if (!baseChannel || baseChannel.isDMBased()) return COUNTS.default;
if (!baseChannel || baseChannel.isDMBased()) return COUNTS.misc;
if (baseChannel.isVoiceBased()) return COUNTS.misc;

return (
{
[config.channels.tickets?.id || ""]: COUNTS.mods,
[config.channels.admin?.id || ""]: COUNTS.admins,
"853256939089559583": COUNTS.misc, // #ba-doosters
"869662117651955802": COUNTS.misc, // #devs-only
"811065897057255424": COUNTS.memes, // #memes
"806609527281549312": COUNTS.memes, // #collabs-and-ideas
"806656240129671188": COUNTS.memes, // #showcase
[config.channels.advertise?.id || ""]: COUNTS.memes,
"939350305311715358": COUNTS.mods, // #modmail
"894314668317880321": COUNTS.mods, // #evil-secret-youtube-plans
}[baseChannel.id] ||
baseReactionCount(baseChannel.id) ??
{
[config.channels.info?.id || ""]: COUNTS.info,
[config.channels.modlogs?.parent?.id || ""]: COUNTS.mods,
"866028754962612294": COUNTS.misc, // #The Cache
}[baseChannel.parent?.id || ""] ||
}[baseChannel.parent?.id || ""] ??
COUNTS.default
);
}
function baseReactionCount(id: Snowflake) {
if (process.env.NODE_ENV !== "production") return COUNTS.scradd;

return {
[config.channels.tickets?.id || ""]: COUNTS.mods,
[config.channels.admin?.id || ""]: COUNTS.admins,
"853256939089559583": COUNTS.misc, // #ba-doosters
"869662117651955802": COUNTS.misc, // #devs-only
"811065897057255424": COUNTS.memes, // #memes
"806609527281549312": COUNTS.memes, // #collabs-and-ideas
"806656240129671188": COUNTS.memes, // #showcase
[config.channels.advertise?.id || ""]: COUNTS.memes,
"939350305311715358": COUNTS.mods, // #modmail
"894314668317880321": COUNTS.mods, // #evil-secret-youtube-plans
}[id];
}

/**
* Generate an embed and button to represent a board message with.
Expand Down
25 changes: 16 additions & 9 deletions modules/reminders/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import constants from "../../common/constants.js";
import { backupDatabases, cleanDatabaseListeners } from "../../common/database.js";
import config from "../../common/config.js";
import { boardDatabase, boardReactionCount } from "../board/misc.js";
import { asyncFilter } from "../../util/promises.js";
import updateBoard from "../board/update.js";

let nextReminder: NodeJS.Timeout | undefined;
Expand Down Expand Up @@ -181,24 +180,32 @@ async function sendReminders(): Promise<undefined | NodeJS.Timeout> {
},
];

const message = await asyncFilter([...boardDatabase.data], async (info) => {
if (info.onBoard) return false;
for (const info of [...boardDatabase.data].sort(() => Math.random() - 0.5)) {
if (info.onBoard) continue;

const reactionsNeeded = boardReactionCount({ id: info.channel });
if (reactionsNeeded !== undefined && info.reactions < reactionsNeeded)
continue;

const channel = await config.guild.channels
.fetch(info.channel)
.catch(() => void 0);
if (!channel?.isTextBased()) return false;
if (!channel?.isTextBased()) continue;

const reactionsNeeded = boardReactionCount(channel);
if (info.reactions < reactionsNeeded) return false;
if (reactionsNeeded === undefined) {
const reactionsNeeded = boardReactionCount(channel);
if (info.reactions < reactionsNeeded) continue;
}

const message = await channel.messages
.fetch(info.source)
.catch(() => void 0);
return message ?? false;
}).next();
if (message) {
await updateBoard(message);
break;
}
}

if (message.value) await updateBoard(message.value);
return;
}
}
Expand Down

0 comments on commit d4bb9e2

Please sign in to comment.