def just_embrace_say(user, clan_name, get_text=False): if not (user or clan_name): return False pander = (clan_name == 'Pander') sir = None if not pander: clan_users = set() not_sire_ids = {user.id}.union(C.not_sir).union(ram.embrace_not) for mem in C.client.get_all_members(): if other.find(mem.roles, id=C.roles[clan_name]) and mem.id not in not_sire_ids: clan_users.add(mem.id) if clan_users: embr_first = [userid for userid in ram.embrace_first if userid in clan_users] if embr_first: sir = embr_first[0] ram.embrace_first.remove(sir) else: sir = other.choice(list(clan_users)) text = com.get_t('embrace_msg', sir=f'<@{sir}>', child=f'<@{user.id}>') else: text = com.get_t('embrace_unic', clan=f'<@&{C.roles[clan_name]}>', child=f'<@{user.id}>') else: text = com.get_t('embrace_pander', child=f'<@{user.id}>') if clan_name in C.sabbat_clans and not pander: text += "\n" + com.get_t('embrace_sabbat') if get_text: return text else: com.write_msg(C.main_ch, text) return sir
def _check_day_ev(now=None, on_midnight=False): global day_ev_check if not now: now = other.get_now() if on_midnight: for ev in data.day_events: if ev in C.events_name: log.jI(f'<Day event> {C.events_name[ev]} finished.') elif ev in C.usernames: log.jI(f'<Day event> {C.usernames[ev]} birthday finished.') data.day_events = set() ev = data_events.date_events.get(now.month, {}).get(now.day, ()) if isinstance(ev, str) or isinstance(ev, int): ev = (ev, ) data.day_events.update(ev) for ev in data.day_events: if ev in C.events_name: log.jI(f'<Day event> Today is {C.events_name[ev]}!') elif ev in C.usernames: log.jI(f'<Day event> Today is {C.usernames[ev]} birthday!') if on_midnight: com.write_msg(C.users['Kuro'], f'<Day event> Today is <@{ev}> birthday!') if not data.day_events: log.jI(f'<Day event> There are no events today.') day_ev_check = now.day
def _timer_check_games(): for usr in user_games: user_games[usr]['h'] += 1 g_name = user_games[usr]['name'].lower() if (usr not in ram.ignore_users and user_games[usr]['h'] % (2 * TMR_IN_H) == 0 and all(word in g_name for word in VTMB)): phr = com.get_t('vtmb', user=f'<@{usr}>') com.write_msg(C.main_ch, phr)
def _check_status_change(user): prob = other.rand() g_key_check = prob < 0.01 g_key = people.online_ev(user.id) if ( g_key_check and user.id not in ram.ignore_users) else False if g_key: gt_key = {'g_key': g_key, 'g_type': 0} phr = com.phrase_gt(gt_key, user.id) if phr: com.write_msg(C.main_ch, phr) people.set_gt(user.id, gt_key['g_key'])
async def on_voice_state_update_u(before, after): """ :type before: C.types.Member :type after: C.types.Member """ global voice_alert_msg v_old = before.voice_channel v_new = after.voice_channel if v_new: on_user_life_signs(after.id) if v_old == v_new: return if v_old and v_new: log.I('<voice> {0} reconnects from #{1} to #{2}.'.format( after, v_old, v_new)) elif v_old: log.I('<voice> {0} disconnects from #{1}.'.format(after, v_old)) elif v_new: log.I('<voice> {0} connects to #{1}.'.format(after, v_new)) note = com.voice_note(after) if note: log.D('<voice> Note event') await other.type2sent(after, note) await _del_voice_alert(after.id) user = None ch = None if (after.id in C.voice_alert and v_new) or (after.top_role > after.server.me.top_role): user = after ch = v_new # type: C.Types.Channel elif v_old and v_old.voice_members and v_old.voice_members[ 0].id in C.voice_alert: user = v_old.voice_members[0] await _del_voice_alert(user.id) ch = v_old # type: C.Types.Channel if user and ch and len(ch.voice_members) == 1 and not other.s_in_s( ('radio', 'радио'), ch.name.lower()): log.D('<voice> Event to @here') every_prm = ch.overwrites_for(ch.server.default_role) if every_prm.connect or (every_prm.connect is None and ch.server.default_role.permissions.connect): va_ids = voice_alert_ids.setdefault(user.id, []) va_msg = voice_alert_msg.setdefault(user.id, []) va_ids.append( com.write_msg(C.main_ch, text=com.voice_event(user, ch), save_obj=va_msg))
def _send_reaction(msg:Msg, m_type, text, edit=False): if not m_type or not text: return log.I(('<reaction.edit>' if edit else '<reaction>') + f'[{m_type}]') if text == 'no-response' or m_type == 'no-response': return if (m_type not in ('rand_tableflip', 'unflip', 'shrug') and ':' not in text and msg.roles.intersection((C.roles['Nosferatu'], C.roles['Malkavian'])) and other.rand() < 0.1): if C.roles['Malkavian'] in msg.roles: text = com.text2malk(text, 1) elif C.roles['Nosferatu'] in msg.roles: text = com.text2leet(text, 0.25) save_obj = _data_msgs_add(msg, m_type) if text != 'no-response' and m_type != 'no-response': _data_tp_add(msg, com.write_msg(msg.channel, text=text, save_obj=save_obj, fun=data_tp_del(msg.channel.id, msg.message.id)))
def _timer_check_silence_in_chat(): if ram.last_vtm_msg and ( (other.get_sec_total() - ram.last_vtm_msg) > 25200): # 7 hours log.I('<timer_quarter_h> silence event!') phr = com.get_t('silence', ) com.write_msg(C.main_ch, phr)
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)
def answer(self, text=None, emb=None): com.write_msg(self.channel, text, emb)