Skip to content

Commit

Permalink
Refactor: contentConverter (#526)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogyuchi authored May 15, 2023
1 parent ab7b079 commit 0569439
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/contentConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,16 @@ import type { Client } from 'discord.js'
const emojiRegex = emojiRegExp()

const dismoji = new Map(
Object.entries(
Object.assign(
activity,
flags,
food,
nature,
objects,
people,
symbols,
travel,
),
)
Object.entries({
...activity,
...flags,
...food,
...nature,
...objects,
...people,
...symbols,
...travel,
})
.map(([key, value]) => [key, (value as string).replace(/\u{FE0F}$/u, '')])
.reverse()
.map(([key, value]) => [value, key]),
Expand Down Expand Up @@ -65,7 +63,7 @@ export const convertContent = (
}

let result = text
.replace(/<(@[!&]?|#)!?([\d]+)>/g, parseContent)
.replaceAll(/<(@[!&]?|#)!?([\d]+)>/g, parseContent)
.replaceAll(URLPattern, '')
.replaceAll(/\|\|.+?\|\|/gs, '')
.replaceAll(/<a?:(\w{2,32}):\d{17,19}>/g, '$1')
Expand All @@ -75,9 +73,7 @@ export const convertContent = (
)
.replaceAll(/~/g, '')
.replaceAll(/\*/g, '')
.replaceAll(emojiRegex, function (x) {
return getShortcodes(x)
})
.replaceAll(emojiRegex, getShortcodes)

return result.match(/(<a?)?:\w+:(\d{18}>)?/) ? '' : result
}
Expand Down

0 comments on commit 0569439

Please sign in to comment.