move create_guild_settings to common.guilds

This commit is contained in:
Luna 2019-10-25 16:19:18 -03:00
parent c765cd7fe0
commit 7c3e9ec2c7
3 changed files with 35 additions and 30 deletions

View File

@ -21,7 +21,12 @@ from typing import Optional, List
from quart import Blueprint, request, current_app as app, jsonify
from litecord.common.guilds import create_role, create_guild_channel, delete_guild
from litecord.common.guilds import (
create_role,
create_guild_channel,
delete_guild,
create_guild_settings,
)
from ..auth import token_check
from ..snowflake import get_snowflake
@ -44,34 +49,6 @@ DEFAULT_EVERYONE_PERMS = 104324161
bp = Blueprint("guilds", __name__)
async def create_guild_settings(guild_id: int, user_id: int):
"""Create guild settings for the user
joining the guild."""
# new guild_settings are based off the currently
# set guild settings (for the guild)
m_notifs = await app.db.fetchval(
"""
SELECT default_message_notifications
FROM guilds
WHERE id = $1
""",
guild_id,
)
await app.db.execute(
"""
INSERT INTO guild_settings
(user_id, guild_id, message_notifications)
VALUES
($1, $2, $3)
""",
user_id,
guild_id,
m_notifs,
)
async def add_member(guild_id: int, user_id: int):
"""Add a user to a guild."""
await app.db.execute(

View File

@ -28,7 +28,6 @@ from ..auth import token_check
from ..schemas import validate, INVITE
from ..enums import ChannelType
from ..errors import BadRequest, Forbidden
from .guilds import create_guild_settings
from ..utils import async_map
from litecord.blueprints.checks import (
@ -39,6 +38,7 @@ from litecord.blueprints.checks import (
)
from litecord.blueprints.dm_channels import gdm_is_member, gdm_add_recipient
from litecord.common.guilds import create_guild_settings
log = Logger(__name__)
bp = Blueprint("invites", __name__)

View File

@ -204,3 +204,31 @@ async def delete_guild(guild_id: int):
# becomes the little memer that tries to fuck up with
# everybody's gateway
await app.dispatcher.remove("guild", guild_id)
async def create_guild_settings(guild_id: int, user_id: int):
"""Create guild settings for the user
joining the guild."""
# new guild_settings are based off the currently
# set guild settings (for the guild)
m_notifs = await app.db.fetchval(
"""
SELECT default_message_notifications
FROM guilds
WHERE id = $1
""",
guild_id,
)
await app.db.execute(
"""
INSERT INTO guild_settings
(user_id, guild_id, message_notifications)
VALUES
($1, $2, $3)
""",
user_id,
guild_id,
m_notifs,
)