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,
|
# 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,8 +332,8 @@ 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,13 +357,15 @@ 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(
|
||||||
'id': str(message_id),
|
'channel', channel_id,
|
||||||
'channel_id': str(channel_id),
|
'MESSAGE_DELETE', {
|
||||||
|
'id': str(message_id),
|
||||||
|
'channel_id': str(channel_id),
|
||||||
|
|
||||||
# for lazy guilds
|
# for lazy guilds
|
||||||
'guild_id': str(guild_id),
|
'guild_id': str(guild_id),
|
||||||
})
|
})
|
||||||
|
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue