Giter Site home page Giter Site logo

Comments (3)

JackDotJS avatar JackDotJS commented on July 27, 2024

update: this was not a simple fix.

from optibot.

JackDotJS avatar JackDotJS commented on July 27, 2024

Currently making some better progress.

Discord handles audit log updates in a somewhat strange way. Any message deleted by a moderator gets sent to the audit log, however messages deleted by the post author does NOT get sent to the log. That's fine, just read the audit logs when a messageDelete event is emitted. However, there's more to it than that.

Messages deleted within a short time frame will be combined into a single log entry. This doesn't sound too bad at first. As you could probably guess from my last late-night message (which I posted with much frustration)... it massively complicates matters.

In the event of deleting multiple messages by multiple different users within a short time frame, Discord will still combine log entries even if they are no longer at the top of the list. This means that entries lower in the list will still be updated if within the same time frame.

My initial idea for logging deleted messages was to simply keep the deletion count in the bots memory, and compare that to the latest audit log entry when a message is deleted. Simply put, if the count from Discords latest audit log was higher than the one in memory, it means the message was deleted by a moderator. (It's slightly more complicated than this, but still.) After further investigation of how audit logs work, this system is COMPLETELY unreliable.

I've resorted to keeping a cache of 10 complete log entries in the bots working memory at all times. Every time the bot detects a deleted message, the bot will call a couple loops to get the latest log containing the same user ID of the author of the deleted message, from both Discord and the bots memory.

I wont lie, this is an pretty heavy operation, especially compared to the other event handlers. The total computation time takes anywhere between 0.2-0.25 seconds. Unfortunately, this seems to be the only surefire and reliable way to tell if a message was deleted by a moderator or the message author. Other than that, it seems to be working. Still need to test with multiple messages and multiple authors at once.

from optibot.

JackDotJS avatar JackDotJS commented on July 27, 2024

Fixed in 26e4a45.
May need additional stress tests.

from optibot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.