def handleGroupInternal(msg): log_info = getRawLogInfo(msg) if isAdminMsg(msg): return log_info if shouldKick(msg.from_user): if kick(msg, msg.from_user): log_info.kicked = 'kicked' else: log_info.kicked = 'should kick' tryDelete(msg) return log_info timeout = shouldDelete(msg) if ((timeout == 0 and veryBadMsg(msg, getSimilarLogs(log_info)[0])) or (str(msg.from_user.id) in mutelist.items())): replyText(msg, '非常抱歉,您的信息被机器人认为有广告的嫌疑,已转交人工审核。审核通过后会归还您发言的权利。', 0.2) tryDelete(msg) log_info.kicked = 'muted all' return log_info if timeout == float('Inf'): return log_info if veryBadMsg(msg, getSimilarLogs(log_info)[0]): log_info.kicked = 'noted' replyText(msg, '非常抱歉,本群不支持转发与多媒体信息,我们将在%d分钟后自动删除您的消息。' % int(timeout + 1), 0.2) td.delete(msg, timeout) log_info.delete = int(timeout) return log_info
def export(update, context): if update.edited_message or update.edited_channel_post: return msg = update.effective_message if msg.chat_id < 0 and 'source</a>' in msg.text_html_urled: return if msg.chat.username == 'web_record': if (matchKey(msg.text_markdown, ['twitter', 'weibo', 'douban', 't.me/']) and not matchKey(msg.text_markdown, ['article', 'note'])): return try: tmp_msg_1 = msg.chat.send_message('received') except: return error = '' result = [] try: result = list(exportImp(msg)) if str(msg.chat.id) in remove_origin._db.items: tryDelete(msg) except Exception as e: tmp_msg_2 = msg.chat.send_message(str(e)) autoDestroy(tmp_msg_2, 0.05) error = ' error: ' + str(e) finally: info_log.send_message(getBasicLog(msg) + error + ' result: ' + ' '.join(result), parse_mode='html', disable_web_page_preview=True) tmp_msg_1.delete()
def export(update, context): if update.edited_message or update.edited_channel_post: return msg = update.effective_message if msg.chat_id < 0 and ('source' in msg.text) and ('[source]' in msg.text_markdown): return if msg.chat.username == 'web_record': if (matchKey(msg.text_markdown, ['twitter', 'weibo', 'douban', 't.me/']) and not matchKey(msg.text_markdown, ['article', 'note'])): tryDelete(msg) return try: r = msg.chat.send_message('received') except: return try: exportImp(msg) if msg.chat.username == 'web_record': tryDelete(msg) except Exception as e: msg.chat.send_message(str(e)) if not matchKey(str(e), ['Content is too big.']): raise e finally: r.delete()
def handleCommand(update, context): msg = update.effective_message if not msg: return handleAdmin(msg) if not msg.text.startswith('/wb'): return command, text = splitCommand(msg.text) if 'unsub' in command: result = subscription.remove(msg.chat_id, text) try: scheduled_key.remove(result) except: ... elif 'sub' in command: result = subscription.add(msg.chat_id, text) scheduled_key.append(result) reply = msg.reply_text(subscription.get(msg.chat_id), parse_mode='markdown', disable_web_page_preview=True) if msg.chat_id < 0: tryDelete(msg) if 'sub' in command: commitRepo(delay_minute=0) if msg.chat_id < 0: autoDestroy(reply, 0.1)
def sendDebugMessage(*args, persistent=False): message = ' '.join([os.uname()[1].split('-')[0]] + [str(x) for x in args]) if persistent: debug_group.send_message(message) return global last_debug_message if last_debug_message: tryDelete(last_debug_message) last_debug_message = debug_group.send_message(message)
def handleAdmin(msg, command, text): if not text: return success = False if command == '/abl': blocklist.add(text) success = True if success: autoDestroy(msg.reply_text('success'), 0.1) tryDelete(msg) commitRepo(delay_minute=0)
def handleCommand(update, context): msg = update.effective_message if msg.text.startswith('/dr'): sendDailyRead(msg, yieldDailyRead) elif msg.text.startswith('/pr'): sendDailyRead(msg, yieldPoliticsRead) elif msg.text.startswith('/daily_hot'): sendDailyHot(msg) else: return tryDelete(msg)
def handleJoin(update, context): msg = update.message kicked = False for member in msg.new_chat_members: if shouldKick(member): tryDelete(msg) logJoin(msg, member, 'kicked on join' if kick(msg, member) else 'should kick on join') kicked = True else: logJoin(msg, member, 'join') if not kicked and not group_settings.get(msg.chat.id, {}).get('log_only'): td.delete(msg, 5) replyText(msg, '欢迎新朋友!新朋友请自我介绍~', 5)
def handleAdmin(msg): if msg.chat.username not in ['b4cxb', 'weibo_read', 'weibo_one']: return command, text = splitCommand(msg.text) if not text: return success = False if command == '/abl': blocklist.add(text) success = True if command == '/apl': popularlist.add(text) success = True if success: autoDestroy(msg.reply_text('success'), 0.1) tryDelete(msg) commitRepo(delay_minute=0)
def sendDailyHot(msg): tryDelete(msg) msg.chat.send_message('【VPN合集】\n\n' + getVPNs()) with open(vpn_filename, 'w') as f: f.write(getVPNs()) msg.chat.send_document(open(vpn_filename, 'rb')) count = 0 for post in getPosts(): if not post.text: continue if not hot_existing.add(''.join(post.text.text[:40].split())): continue if len(post.text.text) > 50: text = getHotText(post.text) count += 1 if count > 10: time.sleep(5) msg.chat.send_message(text, disable_web_page_preview=True)
def search(msg, text, method): reply1 = msg.reply_text('searching') start = time.time() result = method(text, searchCore=True) reply2 = sendResult(msg, result) if reply2: forwardDebug(reply2) forwardDebug(msg) if not goodEnough(result, text): result = method(text) reply3 = sendResult(msg, result) if reply2 and msg.chat.id != debug_group.id: tryDelete(reply2) if not reply3: reply3 = msg.reply_text('no result') forwardDebug(reply3) elif not reply2: # search blocked item (usually p**n related) msg.reply_text('no result') tryDelete(reply1) debug_group.send_message('time elapse: ' + str(time.time() - start))
def handleCommand(update, context): msg = update.effective_message command, text = splitCommand(msg.text) if msg.chat.username in ['twitter_read']: handleAdmin(msg, command, text) if not msg or not msg.text.startswith('/tw'): return success = False if 'unsub' in command: subscription.remove(msg.chat_id, text) success = True elif 'sub' in command: subscription.add(msg.chat_id, text) success = True r = msg.reply_text(subscription.getSubscription(msg.chat_id), parse_mode='markdown', disable_web_page_preview=True) if msg.chat_id < 0: tryDelete(msg) if success: autoDestroy(r, 0.1)
def export(update, context): if update.edited_message or update.edited_channel_post: return msg = update.effective_message if '[source]' in msg.text_markdown and msg.chat_id < 0: return if msg.chat.username == 'web_record': if (matchKey(msg.text_markdown, ['twitter', 'weibo', 'douban', 't.me/']) and not matchKey(msg.text_markdown, ['article', 'note'])): tryDelete(msg) return try: r = msg.chat.send_message('received') except: return exportImp(msg) r.delete() if msg.chat.username == 'web_record': tryDelete(msg)
def toAlbumInternal(update, context): if update.edited_message or update.edited_channel_post: return msg = update.effective_message url = getUrl(msg) if not url: return result = getResult(url, msg.text, getOrigins(msg)) if not result: return if msg.text.endswith(' t'): # text only result.imgs = [] result.video = '' rotate = 0 if msg.text.split()[-1].startswith('r'): try: rotate = int(msg.text.split()[-1][1:]) except: ... tmp_msg = None error = '' final_result = '' send_all = (msg.chat_id == -1001367414473) try: if str(msg.chat_id) in remove_origin._db.items: tryDelete(msg) waitlist_msg = waitlist_log.send_message(msg.text) else: tmp_msg = tele.bot.send_message(msg.chat_id, 'sending') final_result = album_sender.send_v2(msg.chat, result, rotate = rotate, send_all=send_all)[0] if final_result and str(msg.chat_id) in remove_origin._db.items: tryDelete(waitlist_msg) except Exception as e: error = ' error: ' + str(e) if final_result: final_result = final_result.text_html_urled or final_result.caption_html_urled if final_result: final_result = ' result: ' + final_result info_log.send_message(getBasicLog(msg) + error + final_result, parse_mode='html', disable_web_page_preview=True) if tmp_msg: tryDelete(tmp_msg)
def handleCommand(update, context): msg = update.effective_message if not msg or not (msg.text.startswith('/web') or msg.text.startswith('/abl ')): return command, text = splitCommand(msg.text) if 'remove' in command: text = text.strip('/') db.sub.remove(msg.chat_id, text) try: scheduled.remove(text) except: ... elif 'add' in command: config = text.split() site = config[0].strip('/') config = normalizeConfig(config[1:]) db.sub.add(msg.chat_id, site, config) scheduled.append(site) elif 'backfill' in command: tryDelete(msg) backfill(msg.chat_id) elif command == '/abl': text = text.strip() if tooShort(text): reply = msg.reply_text('too short') elif text in blocklist.get(msg.chat_id, []): reply = msg.reply_text('block item already exist') else: blocklist[msg.chat_id] = blocklist.get(msg.chat_id, []) + [text] with open('blocklist', 'w') as f: f.write(yaml.dump(blocklist, sort_keys=True, indent=2, allow_unicode=True)) reply = msg.reply_text('success') autoDestroy(reply, 0.05) tryDelete(msg) if msg.text.startswith('/web'): reply = msg.chat.send_message(db.sub.get(msg.chat_id), disable_web_page_preview=True) tryDelete(msg) if matchKey(msg.text, ['add', 'remove']): autoDestroy(reply, 0.05)