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
def _check_queue(ch_id): queue = msg_queue.get(ch_id, []) if not queue: return count = msg_type_count.get(ch_id, 0) if count < 1: if queue[0] in msg_args: msg_type_count[ch_id] = msg_type_count.get(ch_id, 0) + 1 other.later_coro(0, _send_msg(*msg_args.pop(queue[0]))) else: log.W('com._check_queue, lost msg with id ', queue.pop(0)) _check_queue(ch_id)
async def load(): t1 = os__getmtime('d/data_to_process.py') t2 = os__getmtime('d/data_to_use.py') if t1 > t2: log.W( f'Date of "data_to_process.py" is {other.sec2ts(t1, "%d/%m/%y %H:%M:%S", check_utc=False)}, ' f'when "data_to_use.py" from {other.sec2ts(t2, "%d/%m/%y %H:%M:%S", check_utc=False)} ' f'=> try to recreate "data_to_use".') com.make_d2u() load_texts_used() load_mem() await people.get() # check=(not C.is_test) _check_day_ev() await _load_messages()
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')
async def silence_end(name): user = await silence_off(name) if user: await C.client.send_message(C.main_ch, content='<@{0}>, период твоего торпора подошёл к концу.'.format(user.id)) else: log.W('End silence for ', name, ", but can't find user.")