Skip to content

Commit

Permalink
better match/regex
Browse files Browse the repository at this point in the history
  • Loading branch information
Techbot121 authored and Meta Construct committed Dec 24, 2023
1 parent 39677d0 commit e9dd016
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
8 changes: 3 additions & 5 deletions app/services/discord/modules/discord-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ export default (bot: DiscordBot): void => {
usr.roles.add(DiscordConfig.roles.event);
});
for (const { icon, triggers } of events) {
let match = false;
for (const trigger of triggers) {
if (event.name.toLowerCase().match(new RegExp(`${trigger}\\s`)))
match = true;
}
const match = new RegExp(triggers.join("\\b|").slice(0, -1)).test(
event.name.toLowerCase()
);
if (match) {
await event.guild?.setIcon(join(iconsPath, `${icon}.png`));
break;
Expand Down
8 changes: 4 additions & 4 deletions app/services/discord/modules/shitposting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,13 @@ export default async (bot: DiscordBot) => {
const rng = Math.random();

// triggers
const isTriggerWord = TRIGGER_WORDS.some(str =>
msg.content.toLowerCase().match(new RegExp(`\\b${str}\\b`))
const isTriggerWord = new RegExp(TRIGGER_WORDS.join("\\b|").slice(0, -1)).test(
msg.content.toLowerCase()
);
const isMaybeTriggerWord =
rng <= MAYBE_TRIGGER_FREQ &&
MAYBE_TRIGGER_WORDS.some(str =>
msg.content.toLowerCase().match(new RegExp(`\\b${str}\\b`))
new RegExp(MAYBE_TRIGGER_WORDS.join("\\b|").slice(0, -1)).test(
msg.content.toLowerCase()
);
const isChatChannel = bot.config.channels.chat === msg.channelId;
const isBot = msg.author.id === id;
Expand Down

0 comments on commit e9dd016

Please sign in to comment.