Пример #1
0
async def on_member_remove_u(member):
    # it's triggers on 'go away', kick and ban
    if not other.find(await C.client.get_bans(C.prm_server), id=member.id):
        people.Gn.check_new(member)
        log.pr_news('{0} ({0.mention}) go away!'.format(member))
        await C.client.send_message(
            C.main_ch, com.bye_msg(member.id, member.display_name))
Пример #2
0
async def on_server_role_update_u(before, after):
    upd_server()
    if after.position == before.position + 1 or after.position == before.position - 1:
        return
    names = (before.name + '/' + after.name + ' {@&' + after.id +
             '}' if before.name != '@everyone' else '`@everyone`')

    log.pr_news('Update Role: ' + names + '!')
Пример #3
0
async def on_server_emojis_update_u(before, after):
    la = len(after)
    lb = len(before)
    # before, after - list of server emojis
    if la < 1 and lb < 1:
        return
    log.pr_news('on_server_emojis_update!')
    emj.save_em()
Пример #4
0
async def on_member_join_u(member):
    uid = member.id

    if uid in ram.silence_users:
        t = ram.silence_users[uid]['time'] - other.get_sec_total()
        if t > 0:
            log.I(member, ' come, but Silence is on.')
            await manager.silence_on(uid, t / 3600)
            timer_quarter_h()

    if people.Usr.check_new(member):
        not_embrace.add(uid)
        log.pr_news('{0} ({0.mention}) comeback!'.format(member))
        await C.client.send_message(
            C.main_ch,
            com.comeback_msg(uid, people.time_out(uid), people.clan(uid)))
    else:
        log.pr_news('{0} ({0.mention}) new!'.format(member))
Пример #5
0
async def on_server_role_delete_u(role):
    upd_server()
    log.pr_news('Delete Role: ' + role.name + '!')
Пример #6
0
async def on_server_role_create_u(role):
    upd_server()
    log.pr_news('New Role: ' + role.name + ' {@&' + role.id + '}!')
Пример #7
0
async def on_member_unban_u(server, user):
    people.on_unban(user)
    await C.client.send_message(C.main_ch, com.unban_msg(user.id))
    log.pr_news('Unban {0} ({0.mention})!'.format(user))
Пример #8
0
async def on_member_ban_u(member):
    await people.on_ban(member)
    log.pr_news('Ban {0} ({0.mention})!'.format(member))
    await C.client.send_message(C.main_ch,
                                com.ban_msg(member.id, member.display_name))
Пример #9
0
async def on_member_update_u(before: C.Types.Member, after: C.Types.Member):
    # it's triggers on changing status, game playing, avatar, nickname or roles
    #
    if after.id == C.users['bot']:
        return

    smth_happend = False
    a_n = other.uname(after) + f' [{after.id}]'

    if before.display_name != after.display_name or before.name != after.name:
        smth_happend = True
        b_n = other.uname(before)
        log.pr_news(f'<on_member_update> {b_n} change nickname to {a_n}.')

    if before.game != after.game:
        smth_happend = True
        if before.game and after.game:
            log.D(
                f'<on_member_update> {a_n} go play from {before.game.name} to {after.game.name}.'
            )
        elif before.game:
            log.D(f'<on_member_update> {a_n} stop play {before.game.name}.')
        elif after.game:
            log.D(f'<on_member_update> {a_n} start play {after.game.name}.')
        else:
            log.D(
                f'<on_member_update> {{???}} {a_n} - game change, but there are no games...'
            )

        if after.id == C.users['Natali']:
            if before.game and C.prm_server.me.game.name == before.game.name:
                await other.set_game('')
            if after.game and not C.prm_server.me.game:
                await other.set_game(after.game.name)

        user_g = user_games.pop(after.id, {'name': '', 'h': 0})
        # degradation
        if False and other.rand() < 0.5 and (
                before.game and before.game.name
                and after.id not in ram.ignore_users and people.was_writing(
                    after.id, 48) and user_g['h'] >= TMR_IN_H):
            phr = com.get_t('game',
                            user=f'<@{after.id}>',
                            game=f"«{user_g['name']}»")
            com.write_msg(C.main_ch, phr)

        if after.game and after.game.name:
            user_games[after.id] = {'name': after.game.name, 'h': 0}

    if before.avatar_url != after.avatar_url:
        smth_happend = True
        urls = []
        for url in (before.avatar_url, after.avatar_url):
            urls.append(' ?'.join(url.split('?', maxsplit=1)))
        b_url, a_url = urls

        if before.avatar_url and after.avatar_url:
            await log.pr_avs(
                f'<on_member_update> {a_n} change avatar from \n{a_url} \nto\n{b_url}'
            )
        elif before.avatar_url:
            await log.pr_avs(
                f'<on_member_update> {a_n} delete avatar: \n{b_url}')
        elif after.avatar_url:
            await log.pr_avs(f'<on_member_update> {a_n} set avatar: \n{a_url}')
        else:
            log.I(
                f'<on_member_update> {{???}} {a_n} - avatar change, but there are no avatar_urls...'
            )

        # small degradation
        if (other.rand() < 0.01 and after.avatar_url
                and after.id not in ram.ignore_users
                and people.was_writing(after.id, 48)):
            phr = com.get_t('new_avatar', user=f'<@{after.id}>')
            com.write_msg(C.main_ch, phr)

    if before.roles != after.roles:
        smth_happend = True
        old_roles = [('@&' + r.name) for r in before.roles
                     if r not in after.roles]
        new_roles = [('@&' + r.name) for r in after.roles
                     if r not in before.roles]
        if old_roles:
            log.pr_news(
                f'<on_member_update> {a_n} lost role(s): {", ".join(old_roles)}.'
            )
        if new_roles:
            log.pr_news(
                f'<on_member_update> {a_n} get role(s): {", ".join(new_roles)}.'
            )
            new_role_ids = {r.id for r in after.roles if r not in before.roles}
            new_clan_roles = C.clan_ids.intersection(new_role_ids)
            has_clan_before = other.has_roles(before, C.clan_ids)
            if after.id not in not_embrace and new_clan_roles and not has_clan_before:
                clan_id = other.choice(new_clan_roles)
                clan_name = C.role_by_id[clan_id]
                log.pr_news(
                    f'<on_member_update> {a_n} get new clan role "{clan_name}" => call do_embrace.'
                )
                manager.just_embrace_say(after, clan_name=clan_name)
                # if sir_id:
                #     if clan_id in C.clan_channels:
                #         clan_ch = C.clan_channels[clan_id]
                #         phr = com.get_t(all_keys=('clan_welcome', clan_ch), user=f'<@{after.id}>', sir=f'<@{sir_id}>')
                #         com.write_msg(clan_ch, phr)

            elif has_clan_before and C.roles['Pander'] in new_clan_roles:
                log.jI(
                    f'<on_member_update> {a_n} go to Pander => delete other clan roles if it\'s exist.'
                )
                del_clans_id = C.clan_ids.difference({C.roles['Pander']})
                rem_roles = {r for r in after.roles if r.id in del_clans_id}
                if rem_roles:
                    other.rem_roles(after, rem_roles, 'on_member_update_u[1]')
                    str_rem_r = f"<@&{'>, <@&'.join(r.id for r in rem_roles)}>"
                    phr = com.get_t('to_Pander',
                                    user=f'<@{after.id}>',
                                    old_clans=str_rem_r,
                                    pander=f"<@&{C.roles['Pander']}>")
                    com.write_msg(C.main_ch, phr)
            elif C.roles['Mortal'] in new_role_ids:
                if has_clan_before:
                    # go to food
                    rem_roles = {
                        r
                        for r in after.roles
                        if r.id not in C.mortal_can_have_roles
                    }
                    other.rem_roles(after, rem_roles, 'go to Mortal(food)')
                    log.pr_news(f'<on_member_update> {a_n} go to food')
                else:
                    # new user
                    await C.client.send_message(C.main_ch,
                                                com.welcome_msg(before.id))
                    log.pr_news(f'<on_member_update> {a_n} welcome')

            if C.roles['Sabbat'] in new_role_ids:
                clan_ch = C.clan_channels[C.roles['Sabbat']]
                phr = com.get_t(all_keys=('clan_welcome', clan_ch),
                                user=f'<@{after.id}>')
                com.write_msg(clan_ch, phr)

    if before.status != after.status or not smth_happend:
        people.online_change(after.id,
                             after.status,
                             force=before.status == after.status)
        # small degradation
        _check_status_change(after)

    if (smth_happend
            or people.is_online(after.id)) and before.roles == after.roles:
        on_user_life_signs(after.id)
Пример #10
0
async def check_now():
    log.I('- start check people')
    s_mems = set()
    # noinspection PyTypeChecker
    for mem in C.vtm_server.members:  # type: C.Types.Member
        s_mems.add(mem.id)
        uname = other.uname(mem)
        if mem.id not in usrs:
            if Usr.check_new(mem):
                if gone[mem.id].ban:
                    log.pr_news(f'New user {uname} from ban!')
                else:
                    log.pr_news(f'New user {uname} from gone!')
            else:
                log.pr_news(f'New user {uname}!')
        elif usrs[mem.id].name != uname:
            usrs[mem.id].set(name=uname, status='upd')

        online_now = str(mem.status) != 'offline'
        sec_now = other.get_sec_total()
        frm = '[%d.%m.%y]%H:%M:%S' if (
            sec_now - usrs[mem.id].last_st) >= 86400 else '%H:%M:%S'
        s_now = f'~{other.sec2ts(sec_now, frm=frm)}~'

        if usrs[mem.id].online and online_now:
            users_online[mem.id] = [[
                other.sec2ts(usrs[mem.id].last_st, frm=frm), s_now
            ]]
        elif online_now:
            users_online[mem.id] = []
        elif usrs[mem.id].online:
            users_online[mem.id] = [[
                other.sec2ts(usrs[mem.id].last_st, frm=frm)
            ]]
        else:
            users_online[mem.id] = [[f'{{{s_now}}}']]

        online_change(mem.id, status=str(mem.status), st_now=s_now)

    for usr in usrs:
        if usr not in s_mems:
            usrs[usr].go()
            log.pr_news('User ' + usrs[usr].name + ' disappeared! [Ban: ' +
                        str(gone[usr].ban) + ']')

    for u_ban in bans:
        if u_ban.id not in gone:
            if Gn.check_new(u_ban):
                log.pr_news('New ban user ' + gone[u_ban.id].name +
                            ' from users!')
            else:
                log.pr_news('New ban user ' + gone[u_ban.id].name +
                            ' from somewhere!')
        else:
            if gone[u_ban.id].toban(True):
                log.pr_news('New ban user ' + gone[u_ban.id].name +
                            ' from gone!')

    if bans_id:
        for gn in gone:
            if gn not in bans_id:
                if gone[gn].toban(False):
                    log.pr_news('User ' + gone[gn].name + ' not in ban now!')

    log.I('+ finished check people')