Automod System
I realized if I say 3 bad words fast enough it won't trigger the automod, why could this happend?
Code:
https://pastebin.com/cy6T1Re2
Pastebin
Pastebin.com - Locked Paste
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
33 Replies
Since event listeners are triggered concurrently, and you there is a lot of async functionality in the listener, you're in a situation where messages sent in quick succession might not be fully processed before the next one arrives. i.e.:
message 1 is detected
data 1 is fetched from the db
message 2 is detected
data 2 is fetched from the db
new data is written to the db from message 1 (not fast enough!)
new data is written to the db from message 2
The easiest solution, in my opinion, is to use ![kekw](https://cdn.discordapp.com/emojis/834124742741983312.png)
@sapphire/async-queue
, which will ensure that the messages are processed sequentially. Example:
One potential performance concern would be that this would process all messages sequentially when you really only care about processing an individual's messages sequentially (and doing this concurrently for all individuals). This could be solved by creating a different queue for each person (I'll leave that as an exercise to the reader ![kekw](https://cdn.discordapp.com/emojis/834124742741983312.png)
instead of
// ...
I put the rest of my code rightThe best way for that would probably be
Map<string, Queue>
, and just add a new entry for each user. As a form of cache invalidation, you can check before queue.shift()
if there are no other promises (queue.promises
), remove it from the map
Yes (although use your discretion)Got an error:
You didn't create the queue variable. As I said, use your discretion. Make sure you understand the library and how to use it (it's a small library, so reading the source code might be best).
GitHub
utilities/packages/async-queue/src/lib/AsyncQueue.ts at main · sapp...
Common JavaScript utilities for Sapphire Projects. Contribute to sapphiredev/utilities development by creating an account on GitHub.
It's more productive for you to learn how it works than for me to microedit your code
Added this, (not sure if it's correct), it doesn't log any error now, but it also still doesn't work
Please send the full code. Also,
automod
and automodMute
both return promises, so you have to await them if you want to use the queue effectively.
You also should await the message.channel.send
and message.delete
(Or, if you want to make it fast, use Promise.all
and resolve the promises all at once.)updated code:
https://pastebin.com/cy6T1Re2
Pastebin
Pastebin.com - Locked Paste
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
The queue should be defined outside of the listener so it can maintain state between function calls.
done
any way of making it delete the command instantly?
Delete the command?
message I meant
Order your promises consciously. If you want to delete the message before you check the DB, do that. If you want to do both at the same time, use Promise.all. if you want to register the infraction in the DB before sending the message, do that. If you want to do it at the same time, use Promise.all.
Order your promises considering your priorities
Maybe you want to delete the message while querying the DB while sending the confirmation message, then register the infraction in the DB, then unshift the queue
Often you want the visible things to happen first to give the illusion (whether true or false) of things being fast
In situations such as sending the confirmation message early, this is called an optimistic update.
Sorry that's a bunch of word jumble it's late lol