Ejemplo n.º 1
0
def update_should_verify(g_id):
    g = Guild.objects(guild_id=g_id).first()
    if not g:
        raise exceptions.UpdateError("Cannot update should_verify")
    g.should_verify = not g.should_verify
    g.save()
    return g.should_verify
Ejemplo n.º 2
0
def update_should_save_messages(g_id) -> bool:
    g = Guild.objects().filter(guild_id=g_id).first()
    if not g:
        raise exceptions.UpdateError("Couldn't update 'should_save_message'")
    g.should_save_messages = not g.should_save_messages
    g.save()
    return g.should_save_messages
Ejemplo n.º 3
0
def update_should_show_edited(g_id) -> bool:
    g = Guild.objects(guild_id=g_id).first()
    if not g:
        raise exceptions.UpdateError("Cannot update should_show_edited")
    g.should_show_edited = not g.should_show_edited
    g.save()
    return g.should_show_edited
Ejemplo n.º 4
0
def get_verified_role_in_guild(guild: discord.Guild) -> discord.Role:
    g = Guild.objects(guild_id=guild.id).first()
    r = Role.objects(id__in=g.roles) \
        .filter(category="verify") \
        .first()
    if not r:
        return None
    return guild.get_role(r.role_id)
Ejemplo n.º 5
0
def get_role_from_payload(payload: discord.RawReactionActionEvent,
                          guild: discord.Guild) -> discord.Role:
    g = Guild.objects(guild_id=payload.guild_id).first()
    r = Role.objects(id__in=g.roles) \
        .filter(message_id=payload.message_id) \
        .filter(reaction=payload.emoji.name).first()
    if not r:
        return None
    return guild.get_role(r.role_id)
Ejemplo n.º 6
0
def should_show_deleted_in_guild(g_id) -> bool:
    g = Guild.objects().filter(guild_id=g_id).first()
    if not g:
        raise exceptions.UpdateError("An error has occured")
    if not g.log_channel:
        raise exceptions.UpdateError(
            "There is no log channel set yet.\n Use `!.slc` to assign a channel to logging"
        )
    return g.should_show_deleted
Ejemplo n.º 7
0
def update_guild_welcome_message(guild: discord.Guild, message) -> str:
    g = Guild.objects().filter(guild_id=guild.id).first()
    if not g:
        create_default_guild(guild)
        r = update_guild_welcome_message(guild, messages)
        return r
    g.welcome_message = message
    g.save()

    return g.welcome_message
Ejemplo n.º 8
0
def get_log_channel_in_guild(guild: discord.Guild) -> discord.TextChannel:
    g = Guild.objects().filter(guild_id=guild.id).first()
    if not g:
        raise exceptions.UpdateError("An error has occured")
    if not g.log_channel:
        raise exceptions.UpdateError("There is no log channel set")

    c = guild.get_channel(g.log_channel)
    if not c:
        raise exceptions.UpdateError("Couldn't find the log channel")
    return c
Ejemplo n.º 9
0
def update_should_show_deleted(g_id) -> bool:
    g = Guild.objects().filter(guild_id=g_id).first()
    if not g:
        raise exceptions.UpdateError("Couldn't update 'should_show_deleted'")
    if not g.log_channel:
        raise exceptions.UpdateError(
            "There is no log channel set yet.\n Use `!.slc` to assign a channel to logging"
        )
    g.should_show_deleted = not g.should_show_deleted
    g.save()

    return g.should_show_deleted
Ejemplo n.º 10
0
def create_default_guild(guild: discord.Guild):
    g = get_guild(guild.id)

    if not g:
        g = Guild()
        g.name = guild.name
        g.guild_id = guild.id

        g.welcome_message = messages.DEFAULT_WELCOME_MESSAGE.format(guild.name)
        g.save()
Ejemplo n.º 11
0
def add_guilds(bot, update):
    if ('⛺' in update.message.text or '😴' in update.message.text
        ) and update.message.forward_from_chat.username == 'ChatWarsDigest':
        battletime = update.message.forward_date
        session = db_session.create_session()
        guilds = filter(lambda x: '[' in x, update.message.text.split())
        existing_guilds = [_[0] for _ in session.query(Guild.tag).all()]
        tags = set()
        for guild in guilds:
            tag = guild[0] + guild.split('[')[-1].split(']')[0]
            if tag not in existing_guilds and tag not in tags:
                session.add(Guild(tag=tag))
            tags.add(tag)
        session.commit()
        for tag in tags:
            session.add(
                Battle(guildid=session.query(
                    Guild.id).filter(Guild.tag == tag).one()[0],
                       battletime=battletime.replace(minute=0, second=0)))
        session.commit()
        update.message.reply_text('Результаты сражений приняты.')
Ejemplo n.º 12
0
def increment_retarded_user(g_id):
    Guild.objects(guild_id=g_id).update_one(inc__retarded_user=1)
Ejemplo n.º 13
0
def channel_is_verification(ctx: discord.ext.commands.Context) -> bool:
    return Guild.objects(
        guild_id=ctx.guild.id).first().verification_channel == ctx.channel.id
Ejemplo n.º 14
0
def increment_message_edited(g_id: discord.Guild.id):
    Guild.objects(guild_id=g_id).update_one(inc__message_edited=1)
Ejemplo n.º 15
0
def should_save_messages_in_guild(g_id) -> bool:
    g = Guild.objects().filter(guild_id=g_id).first()
    if not g:
        return False
    return g.should_save_messages
Ejemplo n.º 16
0
def update_log_channel_in_guild(g_id, c_id):
    g = Guild.objects().filter(guild_id=g_id).first()
    if not g:
        raise exceptions.UpdateError("Couldn't set the log channel")
    g.log_channel = c_id
    g.save()
Ejemplo n.º 17
0
def get_guild(g_id):
    return Guild.objects().filter(guild_id=g_id).first()
Ejemplo n.º 18
0
def should_welcome_in_guild(g_id) -> bool:
    g = Guild.objects().filter(guild_id=g_id).first()
    if not g:
        return False
    return g.should_welcome_members
Ejemplo n.º 19
0
def get_password_in_guild(g_id) -> str:
    return Guild.objects(guild_id=g_id).first().password
Ejemplo n.º 20
0
def increment_underaged_user(g_id):
    Guild.objects(guild_id=g_id).update_one(inc__underaged_user=1)
Ejemplo n.º 21
0
def increment_verified_user(g_id):
    Guild.objects(guild_id=g_id).update_one(inc__verified_user=1)