示例#1
0
def prepare_const2():
    log.I('- prepare_const2')
    ev.upd_server()

    C.vtm_news_ch = other.get_channel(C.channels['vtm_news'])
    C.vtm_avs_ch = other.get_channel(C.channels['vtm_avs'])
    C.other_news_ch = other.get_channel(C.channels['other_news'])
    C.vtm_links_ch = other.get_channel(C.channels['vtm_links'])
    C.other_links_ch = other.get_channel(C.channels['other_links'])

    if not (C.vtm_news_ch and C.other_news_ch and C.vtm_links_ch
            and C.other_links_ch):
        log.W("Can't find some of helps channels!.")

    log.I('+ prepare_const2 done')
示例#2
0
def write_msg(ch,
              text=None,
              emb=None,
              extra=0,
              save_obj=None,
              fun: callable = None,
              a_fun: callable = None):
    not_count_sym = {'_', '*', '`'}

    if not text and not emb:
        return ''

    if isinstance(ch, str):
        ch_name = ch
        ch = other.get_channel(ch_name) or other.find_user(ch_name)
        if not ch:
            log.W(f"<write_msg> can't find channel or user {ch_name}.")
            return ''

    if text is None:
        ti, tn = 1, 0
    else:
        ln_text = (len([s for s in text if s not in not_count_sym])
                   if isinstance(text, str) else sum(
                       len([s for s in txt_i if s not in not_count_sym])
                       for txt_i in text))
        tn = min(1500, ln_text) / 30 + extra
        ti = 0

    ident = str(other.t2utc().timestamp())
    msg_queue.setdefault(ch.id, []).append(ident)
    msg_args[ident] = (ident, ti, tn, ch, text, emb, save_obj, fun, a_fun)
    # log.D(f'<write_msg>[add] tn = {tn}, ti = {ti}, ident = {ident}.')
    _check_queue(ch.id)
    return ident
示例#3
0
async def delete_msg(message=None, ch_i=None, msg_id=None, reason='-'):
    if not message:
        try:
            message = await C.client.get_message(other.get_channel(ch_i),
                                                 msg_id)
        except Exception as e:
            other.pr_error(e, 'com.delete_msg.get_message', 'Unexpected error')
            return
    await other.delete_msg(message, reason)
示例#4
0
async def _timer_check_stuff():
    log.jD('timer_check_stuff!')
    msg2del = []  #set()
    now = other.get_sec_total()
    for ch_id in (C.channels['stuff'], C.channels['music']):
        async for msg in C.client.logs_from(
                other.get_channel(ch_id),
                limit=1000000):  #type: C.Types.Message
            msg_time = other.get_sec_total(msg.timestamp)
            if False and now - msg_time > C.h48:
                log.jI(f'break:\n{msg.content}')
                break
            elif now - msg_time > C.h24:
                if not (msg.attachments or msg.embeds or msg.pinned
                        or other.s_in_s(('http://', 'https://', 'www.', '```'),
                                        msg.content)):
                    # msg2del.add(msg)
                    msg2del.append(msg)
    msg2del.reverse()
    for msg in msg2del:
        txt = await log.format_mess(msg)
        log.p(txt)
示例#5
0
async def tree_test():
    import re
    embr_txt = (
        '<@(?P<sir>\d+)> получает право на становление, и <@(?P<child>\d+)> теперь познает всю боль нежизни.',
        '<@(?P<sir>\d+)> дарует становление, но было ли получено разрешение, и что теперь ждёт новоявленое дитя <@('
        '?P<child>\d+)>?',
        '<@(?P<child>\d+)> теперь находится под защитой клана и теперь за ним присмотрит его сир, <@(?P<sir>\d+)>',
        'Не может быть, <@(?P<sir>\d+)> дарует становление неонату <@(?P<child>\d+)> - но является ли это наградой - '
        'или наказанием?',
        'Витэ капнуло тут раз - <@(?P<sir>\d+)> теперь... сир у нас. Что ты об этом думаешь, <@(?P<child>\d+)>?',
    )
    r_txt = []
    for txt in embr_txt:
        r_txt.append(re.compile(txt))
    ch = other.get_channel('flood')
    log.D('- <read> for {0}({1}) start'.format(ch, ch.id))
    messages = []
    count = 0
    async for message in C.client.logs_from(
            ch, limit=1000000000):  #type: C.Types.Message
        if message.author.id == C.users['bot'] and len(message.mentions) == 2:
            messages.append(message)
            count += 1
            if count % 100 == 0:
                log.D('- - <read> save messages: ', count)
    log.D('- <read> end save with {0} messages'.format(count))
    messages.reverse()
    log.D('- <read> start format messages')
    tree = {}
    for msg in messages:
        for r in r_txt:
            m = r.match(msg.content)
            if m:
                d = m.groupdict()
                tree[d['child']] = d['sir']
                log.D(msg.clean_content)
    log.I(tree)
    log.I(len(tree))