Comments (4)
@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.
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.
RMQ is gone already. Where would we need to make use such task system at this point?
from bot.
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)
- Removal of Voice Verified role not logged when using `!tvmute` HOT 3
- Recognise `pyi` snippets as `py` snippets when sharing github/gitlab links HOT 2
- Revert to previous txt file deletion behavior
- Edit eval message instead of deleting and re-sending HOT 1
- Bot
- Update "unambiguous" converters given Discord username changes
- Py
- Make `resources` a slash command. HOT 2
- Automatic invalidation of DIscord bot tokens HOT 2
- Project
- False alerts caused by incorrect regex url for `rich_embed` filter HOT 2
- AttributeError: 'NoneType' object has no attribute 'fetch_message'
- KeyError: AtomicList(id=4, created_at=<Arrow [2023-04-06T16:45:04.133185+00:00]>, updated_at=<Arrow [2023-0...
- Handling of site connection issues during outage. HOT 1
- Log indication of someone trying to voice verify.
- A command to append to a nomination reason HOT 2
- A context menu command to nominate users HOT 7
- Supporting diffs in Github links HOT 1
- Update tests to ensure that infractions sent to the DB are NOT truncated (even if so on Discord's side)
- Forbidden: 403 Forbidden (error code: 40058): Cannot message this thread until after the post author has sen...
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bot.