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)
def test3(): global usrs, gone new_gone = {} for usr in usrs: new_gone[usr] = usrs[usr].go(res=True).set(last=123) new_usrs = {} for gn in gone: new_usrs[gn] = gone[gn].comeback(res=True).set(g_morn=321) usrs = new_usrs gone = new_gone log.p('===========================================')
def timer_quarter_h(): global timer_quarter_works start_quarter_h_timer() try: log.D('+ Quarter hour timer event!') _timer_check_games() _timer_check_silence_in_chat() timer_quarter_works += 1 save() if timer_quarter_works % TMR_IN_H == 0: # hour_timer # other.later_coro(1, _timer_check_stuff()) mn = 4 else: mn = 1 log.D('+ Timer event finished!') log.p('------------------------------------- ' * mn) except Exception as e: other.pr_error(e, 'timer_quarter_h')
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)
async def on_ready(): ram.debug = C.is_test await other.busy() log.I( f'Logged in as {C.client.user} (id: {C.client.user.id}, Test: {C.is_test})' ) prepare_const2() emj.prepare() await ev.load() ram.debug = ram.debug or C.is_test if not discord__opus.is_loaded(): lb = find_library("opus") log.jD('opus lib: ', lb) # i can't find it on heroku if lb: discord__opus.load_opus(lb) else: log.jI('opus lib not load!') ev.start_timers() log.I('Beckett ready for work now, after starting at ', ram.t_start.strftime('[%d/%m/%y %T]')) log.p('======= ' * 10) await test_fun() # for debugging an testing C.Ready = True await other.test_status(ram.game)
def get_properties_and_values(sentence): """ 从一个包含金额的句子中找到对应的款项类别 :param sentence: 待处理的原句子 :return: 从sentence中获取到的所有Property:Value的dict """ quick_get_disabled = False pv_dict = {} # search = re.search(pay_pattern, sentence) # if search: # quick_get_disabled = True cut_words = jieba.lcut(sentence) # if is_abandon(cut_words[0]): # return pv_dict values = re.findall(r'(人民币)?([1-9]\d*\.\d*|0\.\d*[1-9]\d*|[1-9]\d*)(万?)(千?)(亿?)(美?日?元)', sentence) last_index = 0 for j in range(len(values)): for i in range(len(cut_words)): # value[j][1]是sentence中的第j个金额数字,通过下面这个比较,将得出“金额数字”在分词结果的下标(i) if cut_words[i] == values[j][1]: v = values[j][1] if values[j][4] == '亿': v += '00000000' vrb_index = 0 pr_index_list = [] for k in range(1, i - last_index + 1): # i是金额数字的下标 # 从金额数字前的那个词开始,到上一个金额数字的后一个词, # 如果紧挨着的就是property,就立马认可,处理下一个金额数字 # 否则记录这些发现的property的下标 # 如果发现了要abandon的词,就中止对这个数字金额的处理,继续处理下一个 # 如果发现了赔付性动词,则记录这个动词的位置 word_index = i - k seg = cut_words[word_index] if is_property(seg): if k in range(5): if not quick_get_disabled: pv_dict[seg] = v log.p(seg) break else: pr_index_list.append(word_index) continue if is_abandon(seg) and k in range(2): break if is_pay_vrb(seg): vrb_index = word_index if belong_propery(seg): if len(seg) < 3: if word_index - 1 > last_index: log.n(cut_words[word_index - 1] + seg) if word_index not in pr_index_list: pr_index_list.append(word_index) # end for length = len(pr_index_list) if vrb_index > 0 and length > 1: count = 0 while count < length and pr_index_list[count] > vrb_index: count += 1 if count < length: ind = pr_index_list[count] p = cut_words[ind] pv_dict[p] = v log.p(p) last_index = i break if length > 0: p = cut_words[pr_index_list[0]] pv_dict[p] = v log.p(p) break return pv_dict