Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
perf(reviewStrings): use less regex matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Apr 18, 2022
1 parent e06a5d1 commit d163263
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/listeners/messageCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { Stream } from "node:stream"
client.on("messageCreate", async message => {
if (!db) return void cancelledEvents.push({ listener: "messageCreate", args: [message] })

// Delete pinned message and thread created messages
// Delete thread created messages
if (message.type === MessageType.ThreadCreated && (message.channel as TextChannel).name.endsWith("-review-strings"))
return void (await message.delete())

Expand Down Expand Up @@ -54,14 +54,14 @@ client.on("messageCreate", async message => {
const stringURLRegex = /(?:https:\/\/)?crowdin\.com\/translate\/\w+\/(?:\d+|all)\/en(?:-\w+)?(?:\?[\w\d%&=$+!*'()-]*)?#\d+/gi

if (message.channel instanceof TextChannel && message.channel.name.endsWith("-review-strings")) {
if (!stringURLRegex.test(message.content)) await message.delete().catch(() => null)
else if (message.content.match(stringURLRegex)!.length === 1) {
await message.react("vote_yes:839262196797669427")
await message.react("vote_maybe:839262179416211477")
await message.react("vote_no:839262184882044931")
const urls = message.content.match(stringURLRegex)
if (!urls) await message.delete().catch(() => null)
else if (urls.length === 1) {
await message.react("vote_yes:839262196797669427").catch(() => null)
await message.react("vote_maybe:839262179416211477").catch(() => null)
await message.react("vote_no:839262184882044931").catch(() => null)
} else {
const rawText = message.content.split(stringURLRegex),
urls = message.content.match(stringURLRegex)!
const rawText = message.content.split(stringURLRegex)

for (let i = 0; i < urls.length; i++) {
let firstText: string | null = null
Expand Down

0 comments on commit d163263

Please sign in to comment.