mirror of https://gitlab.com/litecord/litecord.git
blueprints.channels: use ChannelDispatcher for MESSAGE_* events
- storage: add Storage.guild_from_channel
This commit is contained in:
parent
37d8114ae2
commit
efefb0cc2f
|
|
@ -285,7 +285,9 @@ async def create_message(channel_id):
|
|||
# we really need dispatch_channel to make dm messages work,
|
||||
# since they aren't part of any existing guild.
|
||||
payload = await app.storage.get_message(message_id)
|
||||
await app.dispatcher.dispatch_guild(guild_id, 'MESSAGE_CREATE', payload)
|
||||
|
||||
await app.dispatcher.dispatch('channel', channel_id,
|
||||
'MESSAGE_CREATE', payload)
|
||||
|
||||
# TODO: dispatch the MESSAGE_CREATE to any mentioning user.
|
||||
|
||||
|
|
@ -330,7 +332,7 @@ async def edit_message(channel_id, message_id):
|
|||
|
||||
# only dispatch MESSAGE_UPDATE if we actually had any update to start with
|
||||
if updated:
|
||||
await app.dispatcher.dispatch_guild(guild_id,
|
||||
await app.dispatcher.dispatch('channel', channel_id,
|
||||
'MESSAGE_UPDATE', message)
|
||||
|
||||
return jsonify(message)
|
||||
|
|
@ -355,7 +357,9 @@ async def delete_message(channel_id, message_id):
|
|||
WHERE messages.id = $1
|
||||
""", message_id)
|
||||
|
||||
await app.dispatcher.dispatch_guild(guild_id, 'MESSAGE_DELETE', {
|
||||
await app.dispatcher.dispatch(
|
||||
'channel', channel_id,
|
||||
'MESSAGE_DELETE', {
|
||||
'id': str(message_id),
|
||||
'channel_id': str(channel_id),
|
||||
|
||||
|
|
|
|||
|
|
@ -840,3 +840,10 @@ class Storage:
|
|||
res.append(drow)
|
||||
|
||||
return res
|
||||
|
||||
async def guild_from_channel(self, channel_id: int):
|
||||
return await self.db.fetchval("""
|
||||
SELECT guild_id
|
||||
FROM guild_channels
|
||||
WHERE id = $1
|
||||
""", channel_id)
|
||||
|
|
|
|||
Loading…
Reference in New Issue