mirror of https://gitlab.com/litecord/litecord.git
guild.roles: fix position of new roles
new roles will always have position 1
This commit is contained in:
parent
ad0aa95f64
commit
04de62778c
|
|
@ -53,10 +53,14 @@ async def create_role(guild_id, name: str, **kwargs):
|
||||||
# TODO: use @everyone's perm number
|
# TODO: use @everyone's perm number
|
||||||
default_perms = dict_get(kwargs, 'default_perms', DEFAULT_EVERYONE_PERMS)
|
default_perms = dict_get(kwargs, 'default_perms', DEFAULT_EVERYONE_PERMS)
|
||||||
|
|
||||||
max_pos = await app.db.fetchval("""
|
# update all roles so that we have space for pos 1, but without
|
||||||
SELECT MAX(position)
|
# sending GUILD_ROLE_UPDATE for everyone
|
||||||
FROM roles
|
await app.db.execute("""
|
||||||
|
UPDATE roles
|
||||||
|
SET
|
||||||
|
position = position + 1
|
||||||
WHERE guild_id = $1
|
WHERE guild_id = $1
|
||||||
|
AND NOT (position = 0)
|
||||||
""", guild_id)
|
""", guild_id)
|
||||||
|
|
||||||
await app.db.execute(
|
await app.db.execute(
|
||||||
|
|
@ -71,10 +75,8 @@ async def create_role(guild_id, name: str, **kwargs):
|
||||||
dict_get(kwargs, 'color', 0),
|
dict_get(kwargs, 'color', 0),
|
||||||
dict_get(kwargs, 'hoist', False),
|
dict_get(kwargs, 'hoist', False),
|
||||||
|
|
||||||
# set position = 0 when there isn't any
|
# always set ourselves on position 1
|
||||||
# other role (when we're creating the
|
1,
|
||||||
# @everyone role)
|
|
||||||
max_pos + 1 if max_pos is not None else 0,
|
|
||||||
int(dict_get(kwargs, 'permissions', default_perms)),
|
int(dict_get(kwargs, 'permissions', default_perms)),
|
||||||
False,
|
False,
|
||||||
dict_get(kwargs, 'mentionable', False)
|
dict_get(kwargs, 'mentionable', False)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue