blueprints.channels: use ChannelDispatcher for MESSAGE_* events

- storage: add Storage.guild_from_channel
This commit is contained in:
Luna Mendes 2018-10-11 22:12:51 -03:00
parent 37d8114ae2
commit efefb0cc2f
2 changed files with 20 additions and 9 deletions

View File

@ -285,7 +285,9 @@ async def create_message(channel_id):
# we really need dispatch_channel to make dm messages work, # we really need dispatch_channel to make dm messages work,
# since they aren't part of any existing guild. # since they aren't part of any existing guild.
payload = await app.storage.get_message(message_id) 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. # 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 # only dispatch MESSAGE_UPDATE if we actually had any update to start with
if updated: if updated:
await app.dispatcher.dispatch_guild(guild_id, await app.dispatcher.dispatch('channel', channel_id,
'MESSAGE_UPDATE', message) 'MESSAGE_UPDATE', message)
return jsonify(message) return jsonify(message)
@ -355,7 +357,9 @@ async def delete_message(channel_id, message_id):
WHERE messages.id = $1 WHERE messages.id = $1
""", message_id) """, message_id)
await app.dispatcher.dispatch_guild(guild_id, 'MESSAGE_DELETE', { await app.dispatcher.dispatch(
'channel', channel_id,
'MESSAGE_DELETE', {
'id': str(message_id), 'id': str(message_id),
'channel_id': str(channel_id), 'channel_id': str(channel_id),

View File

@ -840,3 +840,10 @@ class Storage:
res.append(drow) res.append(drow)
return res 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)