Example #1
0
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
Example #2
0
def cmd_send_log():
    I('Sending log by cmd...')
    drop_path = '/Test_logs/' if C.is_test else '/Logs/'
    now = other.get_now()
    delta = now - ram.t_start
    drop_log_name = 'log_cmd[{0}_{1}]({2}).txt'.format(
        ram.t_start.strftime('{%d|%m|%y %T}'), now.strftime('{%d|%m|%y %T}'),
        other.delta2s(delta))
    dropbox_send(log_full, drop_log_name, drop_path)
    I('Sending log done.')
Example #3
0
def on_final_exit():
    log.I('\n', 'People online data:')
    log.p('\n'.join(people.print_online_people()))
    ram.t_finish = other.get_now()
    ram.t_work = (ram.t_finish - ram.t_start)
    if C.was_Ready:
        save()
    log.I('Finally exit at ', ram.t_finish.strftime('[%D %T]'),
          ', working for ', other.delta2s(ram.t_work))
    log.p('====== ' * 10)
Example #4
0
def prepare_const():
    log.I('- prepare_const')

    st = os__environ.get('Server_Test')
    C.is_test = bool(st) and st not in ('0', 'False', 'false', '')

    C.DISCORD_TOKEN = os__environ.get('DISCORD_TOKEN')

    if not C.DISCORD_TOKEN:
        log.E('Config var DISCORD_TOKEN is not defined.')
        ev.force_exit()

    if C.is_test:
        log.jI('Bot work with Test Server')
    else:
        C.ignore_channels.update(C.test_channels)

    tst_server_key = 'TEST_SERVER_ID'
    tst_channel_key = 'TEST_CHANNEL_ID'
    vtm_server_key = 'VTM_SERVER_ID'
    vtm_channel_key = 'WELCOME_CHANNEL_ID'

    C.VTM_SERVER_ID = os__environ.get(vtm_server_key)
    C.TST_SERVER_ID = os__environ.get(tst_server_key)

    if not C.VTM_SERVER_ID:
        log.E('Config var VTM_SERVER_ID is not defined.')
        ev.force_exit()

    if not C.TST_SERVER_ID:
        log.E('Config var TST_SERVER_ID is not defined.')
        ev.force_exit()

    C.WELCOME_CHANNEL_ID = os__environ.get(vtm_channel_key)
    C.TEST_CHANNEL_ID = os__environ.get(tst_channel_key)

    if not C.WELCOME_CHANNEL_ID:
        log.E('Config var WELCOME_CHANNEL_ID is not defined.')
        ev.force_exit()

    if not C.TEST_CHANNEL_ID:
        log.E('Config var TEST_CHANNEL_ID is not defined.')
        ev.force_exit()

    C.DATABASE_URL = os__environ.get('DATABASE_URL')
    if not C.DATABASE_URL:
        log.E('Config var DATABASE_URL is not defined.')
        ev.force_exit()

    C.DROPBOX_ID = os__environ.get('DROPBOX_ID')

    ram.t_start = other.get_now()
    log.I('+ prepare_const done')
Example #5
0
def timer_midnight_update(now=None):
    if not now:
        now = other.get_now()

    log.I('[=== New day! ===]')

    try:
        _check_day_ev(now, on_midnight=True)
    except Exception as e:
        other.pr_error(e, '_check_day_ev', 'Unexpected error')

    try:
        _check_once_in_day()
    except Exception as e:
        other.pr_error(e, '_check_once_in_day', 'Unexpected error')
Example #6
0
def timer_half_min():
    global day_ev_check
    start_half_min_timer()
    try:
        now = other.get_now()
        sec_total = int(now.timestamp())
        if now.hour == 0 and now.minute == 0 and day_ev_check != now.day:
            timer_midnight_update(now)

        for uid, user in ram.silence_users.items():
            if sec_total > user['time']:
                other.later_coro(1, manager.silence_end(uid))
                other.later(15, timer_quarter_h)
    except Exception as e:
        other.pr_error(e, 'timer_half_min')
Example #7
0
def online_ev(uid):
    if uid not in usrs:
        return False
    usr = usrs[uid]
    if (usr.online and usr.was_stable_for(5) and usr.was_writing(48) and any(
        {usr.gt_was_for(key, 48)
         for key in {'g_morn', 'g_day', 'g_ev'}})):
        corr = 0
        if usr.id == C.users['Tony']:
            corr = -8
        h = other.get_now().hour + corr
        t_day = {'g_morn': (4, 12), 'g_day': (12, 18), 'g_ev': (18, 24)}

        for g_key in t_day:
            t_min, t_max = t_day[g_key]
            if t_min <= h < t_max:
                return g_key if usr.gt_passed_for(g_key, 16) else False
    return False
Example #8
0
def online_change(uid, status, force=False, st_now=''):
    if uid not in usrs:
        return False

    usr = usrs[uid]
    online_now = str(status) != 'offline'

    if not (usr.online != online_now or force):
        return True

    usr_online = users_online.setdefault(uid, [['!']])
    t_now = other.get_now()
    sec_now = other.get_sec_total(t_now)
    frm = '[%d.%m.%y]%H:%M:%S' if (sec_now -
                                   usr.last_st) >= 86400 else '%H:%M:%S'
    s_now = st_now or f'{other.t2s(t_now, frm)}'

    if force:
        ''' if offline -> offline - it can be go in/out invisible user
            if online -> online - open app with open tab in browser
        '''
        if not online_now:  # offline -> offline
            if usr.maybe_invisible:
                usr_online[-1].append(f'{{{s_now}}}')
            else:
                usr_online.append([f'{{{s_now}}}'])

            if usr.was_invisible:
                usr.set_invisible(not usr.maybe_invisible, True)
            else:
                usr.set_invisible(False, False)
            usr.prev_onl = False

        usr.last_force_check = sec_now

    elif online_now:
        if usr.maybe_invisible:
            usr_online[-1].append(f'{s_now}')
        else:
            usr_online.append([f'{s_now}'])
    else:
        usr_online[-1].append(f'{s_now}')

    if not force:
        usr.prev_onl = usr.online
        usr.set_invisible(False)

    if usr.online != online_now or usr.maybe_invisible != usr.prev_inv:
        usr.prev_st = sec_now - usr.last_st
        usr.last_st = sec_now
        # log.jI(f"{usr.name} is {('offline', 'online')[online_now]} now after {other.s2s(usr.prev_st)}")
        usr.online = online_now
        usr.status = 'upd'
        get_for_now = False
    else:
        get_for_now = force and not online_now

    if uid in {
            C.users[usr]
            for usr in ('Dummy', 'Tilia', 'Natali', 'Doriana', 'cycl0ne')
    }:
        log_f = log.jI if st_now else log.I
        log_f('<on_status_update> ' +
              get_online_info_now(uid, get_for_now=get_for_now))

    return True
Example #9
0
def _emj_on_message(msg:Msg, beckett, edit=False):
    message = msg.message
    author = msg.auid

    if author in ram.ignore_users or msg.is_bot:
        return

    pause_and_add, pause_and_rem, e, e_str = emj.pause_and_add, emj.pause_and_rem, emj.e, emj.e_str
    prob = other.rand()

    sm_for_beckett = {
        C.users['Natali']: (*('purple_heart',) * 5, 'relaxed', 'blush',
                                                        'kissing_closed_eyes', 'kissing_heart', 'slight_smile'),
        C.users['Doriana']: ('octopus',),
        C.users['Hadley']: ('a_Toreador_light', 'a_Toreador_wave',),
        C.users['AyrinSiverna']: ('Ankh_Sabbat', 't_torik21', 'Logo_Toreador', 'hearts',),
        C.users['Rainfall']: ('green_heart',),
        C.users['Tony']: ('Logo_Ventrue',),
        C.users['aleth_lavellan']: ('hugging', 'relieved', 'kissing_cat', 'wink', 'flushed'),
    }
    prob_for_beckett = {
        C.users['Natali']: 0.4,
    }
    sm_for_nothing = {
        C.users['Natali']: ('purple_heart', 'heart_eyes', 'heart_eyes_cat'),
        C.users['Doriana']: ('black_heart',),
        C.users['Hadley']: ('Logo_Toreador',),
        C.users['AyrinSiverna']: ('Logo_Toreador',),
        C.users['Rainfall']: ('racehorse',),
        C.users['aleth_lavellan']: ('purple_heart', 'relieved', 'smiley_cat', 'aleth_wink'),
    }
    prob_for_nothing = {
        C.users['Natali']: 0.01,
    }
    sm_by_jiznbol = ('((', 'Π’_Π’', 'T_T', ':Π‘', ':C', '😭', '😒', '😣', 'πŸ˜–', '😫', '😩', 's_blood_cry')
    sm_by_fun = ('))', ':D', 'XD', 'πŸ˜ƒ', '😁', 'πŸ˜€', 'πŸ˜„', 'm_wafer', 'm_Tilia_fase', 'πŸ˜‚', 'πŸ˜†', '😹', '🀣')

    if msg.chid == C.channels['stuff'] and (message.attachments or message.embeds):
        log.jD(f'emj.in_staff, prob = {prob}.')
        if author == C.users['Natali'] and prob < 0.5:
            log.jD('Like Natali in staff')
            pause_and_add(message, ('purple_heart', 'heart_eyes', 'heart_eyes_cat', 'heartpulse'))
        elif author in {C.users['Doriana'], C.users['Tilia'], C.users['Buffy']} and prob < 0.2:
            log.jD('Like Doriana or Tilia or Buffy in staff')
            pause_and_add(message, ('heart', 'hearts', 'heart_eyes', 'black_heart'))
        elif author in {C.users['Hadley'], C.users['cycl0ne'], C.users['Magdavius']} and prob < 0.2:
            log.jD('Like Hadley or cycl0ne or Magdavius in staff')
            pause_and_add(message, ('thumbsup', 'ok_hand', 'heart_eyes_cat'))

    if edit:
        return

    if prob > 0.99:
        if other.s_in_s(sm_by_jiznbol, msg.original):
            pause_and_add(message, ('t_jiznbol1', 't_jiznbol2'))
        elif other.s_in_s(sm_by_fun, msg.original):
            pause_and_add(message, ('smiley', 'slight_smile', 'grin', 'grinning', 'smile', 'upside_down'))

    if beckett and author in sm_for_beckett and prob < prob_for_beckett.get(author, 0.25):
        log.jD(f'Like {C.usernames[author]} for Beckett with chance {prob_for_beckett.get(author, 0.25)}.')
        pause_and_add(message, sm_for_beckett[author])
    elif author in sm_for_nothing and prob < prob_for_nothing.get(author, 0.005):
        log.jD(f'Like {C.usernames[author]} with chance {prob_for_nothing.get(author, 0.005)}.')
        pause_and_add(message, sm_for_nothing[author])
    elif author == C.users['aleth_lavellan'] and other.s_in_s(('ΠΏΠ°ΠΏΠΊΠ°', 'ΠΏΠ°ΠΏΠ°', 'батя'), msg.text):
        pause_and_add(message, ('blush', 'slight_smile', 'cowboy', 'p_beckett1'))

    # Day Events
    if not data.day_events:
        return

    prob = other.rand()
    now = other.get_now()

    # if birthday user is mentioned in msg -> copy emoji from msg under this msg
    if data.day_events.intersection(message.raw_mentions):
        em_in_text = emj.get_em_names(msg.original)
        em_in_text = [emj.e_or_s(em) for em in em_in_text]
        del_em = set()
        for react in msg.message.reactions: # type: C.Types.Reaction
            if react.me and react.count < 2:
                del_em.add(react.emoji)
        common_em = del_em.intersection(em_in_text)
        del_em.difference_update(common_em)
        em_in_text = [em for em in em_in_text if em not in common_em]
        pause_and_rem(message, del_em, t=0, all_=True)
        pause_and_add(message, em_in_text, 1, all_=True)
    # birthday emojis to birthday user
    if author in data.day_events:
        pause_and_add(message, ('πŸŽ‚', '🍰', '🎈', '🎁', '🎊', 'πŸŽ‰', 'πŸ’°', 'πŸ’Έ', 'πŸ’΅', 'πŸ’΄', 'πŸ’Ά', 'πŸ’·',
                                'πŸ–Ό', '🌠', 'πŸŽ‡', 'πŸŽ†', 'πŸ“―', 'πŸ†™', '🎯', '🎰', 'πŸ₯‡', 'πŸ…', 'πŸŽ–', 'πŸ†', 'πŸ’›',))

    if C.events['Valentine\'s Day'] in data.day_events and now.hour > 3:
        if (author in {C.users['Natali'], C.users['Hadley']} or
                ((msg.admin or msg.moder or C.roles['Primogens'] in msg.roles) and prob < 0.25)):
            pause_and_add(message, {'❀', 'πŸ’›', 'πŸ’™', 'πŸ’œ', '❣', 'πŸ’•', 'πŸ’ž', 'πŸ’“', 'πŸ’—', 'πŸ’–', 'πŸ’', 'β™₯'})
        elif prob < 0.1:
            pause_and_add(message, {'πŸ’Œ', 'πŸ’Ÿ', })

    elif C.events['8 March'] in data.day_events and now.hour > 3:
        if author == C.users['Natali'] and prob < 0.1:
            pause_and_add(message, ('a_Toreador_light', 'a_Toreador_wave'))
        elif C.roles['Tzimisce'] in msg.roles:
            pause_and_add(message, 'wilted_rose')
        elif author in C.female:
            if ((msg.admin or msg.moder or C.roles['Primogens'] in msg.roles) and prob < 0.5) or prob < 0.1:
                pause_and_add(message, ('a_open_flower', 'a_rose_grows', 'a_heart_rose', 'a_rose_pulse',
                                        'a_flower_twink', 'a_color_flower', 'a_water_lily', 'a_flower_chameleon'))
            elif C.roles['Toreador'] in msg.roles and prob < 0.2: # 10%: 0.1-0.2
                pause_and_add(message, 'Logo_Toreador')
            else:
                pause_and_add(message, ('🌺', '🌻', '🌹', '🌷', '🌼', '🌸', 'πŸ’'))