mirror of https://gitlab.com/litecord/litecord.git
roles: add GET /api/v6/guilds/:id/roles
- guild: add DELETE /api/v6/guilds/:id/bans/:uid
This commit is contained in:
parent
ce5b75921a
commit
8678c84355
|
|
@ -4,19 +4,31 @@ from quart import Blueprint, request, current_app as app, jsonify
|
|||
|
||||
from litecord.auth import token_check
|
||||
|
||||
# from litecord.blueprints.checks import guild_check
|
||||
from litecord.blueprints.checks import guild_owner_check
|
||||
from litecord.snowflake import get_snowflake
|
||||
from litecord.utils import dict_get
|
||||
|
||||
from litecord.blueprints.checks import (
|
||||
guild_check, guild_owner_check
|
||||
)
|
||||
from litecord.schemas import (
|
||||
validate, ROLE_CREATE, ROLE_UPDATE, ROLE_UPDATE_POSITION
|
||||
)
|
||||
|
||||
from litecord.snowflake import get_snowflake
|
||||
from litecord.utils import dict_get
|
||||
|
||||
DEFAULT_EVERYONE_PERMS = 104324161
|
||||
bp = Blueprint('guild_roles', __name__)
|
||||
|
||||
|
||||
@bp.route('/<int:guild_id>/roles', methods=['GET'])
|
||||
async def get_guild_roles(guild_id):
|
||||
"""Get all roles in a guild."""
|
||||
user_id = await token_check()
|
||||
await guild_check(user_id, guild_id)
|
||||
|
||||
return jsonify(
|
||||
await app.storage.get_role_data(guild_id)
|
||||
)
|
||||
|
||||
|
||||
async def create_role(guild_id, name: str, **kwargs):
|
||||
"""Create a role in a guild."""
|
||||
new_role_id = get_snowflake()
|
||||
|
|
|
|||
|
|
@ -112,6 +112,10 @@ async def create_guild():
|
|||
|
||||
# create the default @everyone role (everyone has it by default,
|
||||
# so we don't insert that in the table)
|
||||
|
||||
# we also don't use create_role because the id of the role
|
||||
# is the same as the id of the guild, and create_role
|
||||
# generates a new snowflake.
|
||||
await app.db.execute("""
|
||||
INSERT INTO roles (id, guild_id, name, position, permissions)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
|
|
@ -314,6 +318,31 @@ async def create_ban(guild_id, member_id):
|
|||
return '', 204
|
||||
|
||||
|
||||
@bp.route('/<int:guild_id>/bans/<int:banned_id>', methods=['DELETE'])
|
||||
async def remove_ban(guild_id, banned_id):
|
||||
user_id = await token_check()
|
||||
|
||||
# TODO: check BAN_MEMBERS permission
|
||||
await guild_owner_check(guild_id, user_id)
|
||||
|
||||
res = await app.db.execute("""
|
||||
DELETE FROM bans
|
||||
WHERE guild_id = $1 AND user_id = $@
|
||||
""", guild_id, banned_id)
|
||||
|
||||
# we don't really need to dispatch GUILD_BAN_REMOVE
|
||||
# when no bans were actually removed.
|
||||
if res == 'DELETE 0':
|
||||
return '', 204
|
||||
|
||||
await app.dispatcher.dispatch_guild(guild_id, 'GUILD_BAN_REMOVE', {
|
||||
'guild_id': str(guild_id),
|
||||
'user': await app.storage.get_user(banned_id)
|
||||
})
|
||||
|
||||
return '', 204
|
||||
|
||||
|
||||
@bp.route('/<int:guild_id>/messages/search')
|
||||
async def search_messages(guild_id):
|
||||
"""Search messages in a guild.
|
||||
|
|
|
|||
Loading…
Reference in New Issue