Coder Social home page Coder Social logo

Replace RMQ with Tasks about bot HOT 4 CLOSED

python-discord avatar python-discord commented on May 18, 2024
Replace RMQ with Tasks

from bot.

Comments (4)

scragly avatar scragly commented on May 18, 2024

@heavysaturn (mentioning as this is a migrated ticket)

I'm unable to see the related issue ticket for this, but this should be super simple to implement, as we don't need to make any special event dispatcher for this; we can just take advantage of bot.dispatch that's already present in the discord.py client. It's fully extensible with custom events.

For example task retrieval could be something like this (abstracting out the actual api fetching code):

tasks = await self.retrive_new_tasks() # gets the tasks from the api endpoint
for task in tasks:
    # example of data would be:
    #   task["task_id"] = "b8b97d2f-13b7-4061-ad38-5245a2d02cda"
    #   task["type"] = "add_role"
    #   task["target_id"] = value of 174764205927432192
    #   task["role_id"] = value of 423054537079783434
    #   task["reason"] = value of "Code Jam approval"

    task_id= task.pop("task_id")
    task_type = task.pop("type")
    task_event = f"task_{task_type}"
    self.bot.dispatch(task_event, **task)

    # tell api it's dispatched to distinguish tasks already actioned
    await self.mark_task_dispatched(task_id)

and then elsewhere that wants to action that task event:

async def on_task_add_role(self, target_id, role_id, reason):
    member = self.guild.get_member(target_id)
    if not member:
        log.info(f"Task 'Add Role' unable to be completed: Member not found ({target_id})
        return

    role = self.guild.get_role(role_id)
    if not role:
        log.info(f"Task 'Add Role' unable to be completed: Role not found ({target_id})
        return

    await member.add_roles(role, reason=reason)

As long as this coroutine for the task event is present in a cog, it'll be detected as a valid event as it starts with on_ and will be used when dispatch emits an event named task_add_role.

Just as a note: PR #289 removes all RMQ totally, effectively actioning this issue, but does not add in support for non-message events the site may want to send (as the site instead is using discord webhooks to send notifications to discord channels). So the above only really applies to all non-messaging events such as role changes.

from bot.

lemonsaurus avatar lemonsaurus commented on May 18, 2024

ohhh, that's a very interesting way to implement this. this isn't a super urgent need, but we'll need it for automating code jam setups. I think I am 100% on board with this approach. also, I did not know that was a thing.

from bot.

MarkKoz avatar MarkKoz commented on May 18, 2024

RMQ is gone already. Where would we need to make use such task system at this point?

from bot.

lemonsaurus avatar lemonsaurus commented on May 18, 2024

The idea was to use it for Code Jam stuff, but frankly this ticket feels really stale and I think it's better we close it and rethink the Code Jam stuff when that time comes.

from bot.

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.