channels: send system messages on name/icon change in gdm

This commit is contained in:
Luna 2019-02-16 23:55:29 -03:00
parent 8a76b5a407
commit ebd4a8a0cd
1 changed files with 11 additions and 2 deletions

View File

@ -23,13 +23,14 @@ from quart import Blueprint, request, current_app as app, jsonify
from logbook import Logger
from litecord.auth import token_check
from litecord.enums import ChannelType, GUILD_CHANS
from litecord.enums import ChannelType, GUILD_CHANS, MessageType
from litecord.errors import ChannelNotFound
from litecord.schemas import (
validate, CHAN_UPDATE, CHAN_OVERWRITE, SEARCH_CHANNEL, GROUP_DM_UPDATE
)
from litecord.blueprints.checks import channel_check, channel_perm_check
from litecord.system_messages import send_sys_message
log = Logger(__name__)
bp = Blueprint('channels', __name__)
@ -405,7 +406,7 @@ async def _update_voice_channel(channel_id: int, j: dict):
await _common_guild_chan(channel_id, j)
async def _update_group_dm(channel_id: int, j: dict):
async def _update_group_dm(channel_id: int, j: dict, author_id: int):
if 'name' in j:
await app.db.execute("""
UPDATE group_dm_channels
@ -413,6 +414,10 @@ async def _update_group_dm(channel_id: int, j: dict):
WHERE id = $2
""", j['name'], channel_id)
await send_sys_message(
app, channel_id, MessageType.CHANNEL_NAME_CHANGE, author_id
)
if 'icon' in j:
new_icon = await app.icons.update(
'channel-icons', channel_id, j['icon'], always_icon=True
@ -424,6 +429,10 @@ async def _update_group_dm(channel_id: int, j: dict):
WHERE id = $2
""", new_icon.icon_hash, channel_id)
await send_sys_message(
app, channel_id, MessageType.CHANNEL_ICON_CHANGE, author_id
)
@bp.route('/<int:channel_id>', methods=['PUT', 'PATCH'])
async def update_channel(channel_id):