0
votes

I am using regex to change my translation bot sending custom emojis. By doing this I can remove unsupported unlatin names and whitespaces:

data.text.replace(/:.*?:/, ":okthisisanemoji:"); This works fine and the translator does send custom emojis now but I want it to loop until the only thing that is inbetween any : is :okthisisanemoji: .

Right now I cant do more than one ethically because a normal loop would just replace :okthisisanemoji: forever.

Can someone help describe to me how to create a loop which replaces the string of < : translatedemojiname : emojiID> to <:okthisisanemoji:emojiID> but for every emoji sent in the message instead of only the last or first 3-4.

Code is this:

   if (data.author)
   {
      if (data.text.includes("<:")) 
// -> data.text = <: gelb:590653333124022288>
      {
         data.text = data.text.replace(/:.*?:/, ":okthisisanemoji:"); 
// -> <:okthisisanemoji:590653333124022288>     ( but right now it does not do it for everything.
         data.text = data.text.replace(": ", ":"); // -> "ABCDEFGHSTUVWXYZ"
         data.text = data.text.replace("<: ", "<:");
      }
   }

Discord

The source code is here: https://github.com/Zyc0r3/RitaBot/tree/emoji

And the file is https://github.com/ZyC0R3/RitaBot/blob/emoji/src/core/send.js

It's a translation bot for Discord and right now the custom emoji is a problem. Please help

Website is here: https://ritabot.org

Discord Server is here: https://discord.gg/NAxA3nf

1
Do you mean you want to find any text between : except okthisisanemoji? Try /:(?!okthisisanemoji:).*?:/Wiktor Stribiżew
I want to replace the data.text string from the translated emoji name and whitespaces to <:okthisisanemoji:emojiIDdisplayed> I can do one emoji at a time right now per message but it cant do many at once. I need it to do every string between : : at once. Like .replaceAll in Java to replace :translatedname : with :okthisisanemoji:Artanis

1 Answers

2
votes

Using regex

<(:\s*[a-z]+:\s*)([0-9]+)>

Regex Demo

const text = `<:Gelb: 590653333124022288><:Gelb: 590653333124022288><: Gelb: 590653333124022288> <: Gelb: 590653333124022288><: Gelb: 590653333124022288><: Gelb: 590653333124022288>
<: Gelb: 590653333124022288> <: Gelb: 590653333124022288>
<: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288>
<: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288>
<: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288>
<: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288>
<: Gelb: 590653333124022288> <okthisisanemoji:5906533331 24022288><:Gelb:
590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb:
590653333124022288> <: Gelb: 590653333124022288> <: Gelb: 590653333124022288> <: Gelb:
590653333124022288>
<:Gelb: 590653333124022288>
<:Rot: 590653332616511496>`

const regx = /<:\s*[a-z]+\s*:\s*([0-9]+)>/mgi

console.log(text.replace(regx, '<:okthisisanemoji:$1>'))