blueprints.{channels, guilds}: use *Type as enums instead of classes

This commit is contained in:
Luna Mendes 2018-09-10 20:29:04 -03:00
parent ee8cfedf69
commit 952b66a28c
2 changed files with 7 additions and 5 deletions

View File

@ -23,7 +23,7 @@ async def channel_check(user_id, channel_id):
if ctype is None:
raise ChannelNotFound(f'channel type not found')
if ctype in (ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE,
if ChannelType(ctype) in (ChannelType.GUILD_TEXT, ChannelType.GUILD_VOICE,
ChannelType.GUILD_CATEGORY):
guild_id = await app.db.fetchval("""
SELECT guild_id
@ -116,7 +116,7 @@ async def create_message(channel_id):
j.get('tts', False),
'@everyone' in j['content'],
int(j.get('nonce', 0)),
MessageType.DEFAULT
MessageType.DEFAULT.value
)
# TODO: dispatch_channel

View File

@ -69,7 +69,7 @@ async def create_guild():
await app.db.execute("""
INSERT INTO channels (id, channel_type)
VALUES ($1, $2)
""", general_id, ChannelType.GUILD_TEXT)
""", general_id, ChannelType.GUILD_TEXT.value)
await app.db.execute("""
INSERT INTO guild_channels (id, guild_id, name, position)
@ -211,6 +211,8 @@ async def create_channel(guild_id):
new_channel_id = get_snowflake()
channel_type = j.get('type', ChannelType.GUILD_TEXT)
channel_type = ChannelType(channel_type)
if channel_type not in (ChannelType.GUILD_TEXT,
ChannelType.GUILD_VOICE):
raise BadRequest('Invalid channel type')
@ -218,7 +220,7 @@ async def create_channel(guild_id):
await app.db.execute("""
INSERT INTO channels (id, channel_type)
VALUES ($1, $2)
""", new_channel_id, channel_type)
""", new_channel_id, channel_type.value)
max_pos = await app.db.fetch("""
SELECT MAX(position)