def marry(bot, update, args): # 結婚就是墳場 mongo = db_tools.use_mongo() if len(args) < 2: update.message.reply_text('參數過少。') return elif len(args) > 2: update.message.reply_text('參數過多。') return try: uid = int(args[0]) except BaseException: update.message.reply_text('UID 參數錯誤') return else: level = args[1] if level not in ['elf', 'michael', 'lucifer']: update.message.reply_text('等級 參數錯誤') return if sage.lucifer(update.message.from_user.id): if sage.is_sage(uid): mongo.class_level.find_one_and_update({}, {'$pull': {level: uid}}) update.message.reply_text('拔掉頭環惹').result() sage.refresh() return else: update.message.reply_text('這不是天使吧??') return
def pregnant(bot, update, args): # /add 123 lucifer mongo = db_tools.use_mongo() if len(args) < 2: update.message.reply_text('參數過少。') return elif len(args) > 2: update.message.reply_text('參數過多。') return try: uid = int(args[0]) except BaseException: update.message.reply_text('UID 參數錯誤') return else: level = args[1] if level not in ['elf', 'michael', 'lucifer']: update.message.reply_text('等級 參數錯誤') return if sage.lucifer(update.message.from_user.id): if sage.is_sage(uid): update.message.reply_text('已經有職位了。') return user = mongo.user.find_one({'chat.id': uid}) if user is None: update.message.reply_text('我不認識這人啊 誰啊?') return mongo.class_level.find_one_and_update({}, {'$addToSet': {level: uid}}) update.message.reply_text('🆙️ 升級完成').result() sage.refresh()
def groupconfig(bot, update): i18n(update).loads.install(True) mongo = db_tools.use_mongo() try: update.message.delete() except BaseException: pass users = bot.get_chat_member(update.message.chat.id, update.message.from_user.id) if is_admin(bot, update) == False or sage.lucifer( update.message.chat.id) == False: text = _('你不是管理員好嗎,請不要亂打擾我。') sent = update.message.reply_text(text).result() time.sleep(5) sent.delete() return text = f'<code>{escape(update.message.chat.title)}</code>\n' + \ _('📋 訂閱黑名單列表\n') + \ _('本清單預設開啟 "兒童色情內容" \n') + \ _('✅ - 開啟訂閱\n') + \ _('❌ - 關閉訂閱') keyboard = generate.inline_groupconfig(bot, update, 0) sent = update.message.reply_text(text, parse_mode='html', reply_markup=keyboard) mongo.group.find_one_and_update( {'chat.id': update.message.chat.id}, {'$set': { 'chat.config.configuring': sent.result().message_id }})
def xfilter_refresh(): redis = db_tools.use_redis() mongo = db_tools.use_mongo() result = mongo.xtext_filter.find() redis.delete('xtext_filter') for x in list(result): redis.lpush('xtext_filter', x['rule']) return True
def add_wl(bot, update, args): i18n(update).loads.install(True) if len(args) == 0: try: update.message.delete() except BaseException: pass return if sage.is_sage(update.message.from_user.id): if sage.lucifer(update.message.from_user.id) == False: try: update.message.delete() except BaseException: pass text = '你等級不夠 🌚\n最低等級要求是 <code>Lucifer</code>' update.message.reply_html(text) return else: try: update.message.delete() except BaseException: pass return mongo = db_tools.use_mongo() if len(args) > 1: update.message.reply_text(_('傳入過多參數。')) return try: uid = int(args[0]) except BaseException: update.message.reply_html(_(f'UID <code>{args[0]}</code> 解析錯誤 ')) return if uid > 9999999999: update.message.reply_text(_('傳入怪怪的 UID 參數。')) return query_user = mongo.user.find_one({'chat.id': uid}) if query_user: user = db_parse.user() user.parse(query_user) if user.is_white: text = _(f'<code>{uid}</code> 已在白名單內') update.message.reply_html(text) else: mongo.user.find_one_and_update({'chat.id': uid}, {'$set': { 'chat.is_white': True }}) text = _('已更新全域白名單 ✅') update.message.reply_text(text) else: update_user = {'chat': {'id': uid, 'is_white': True}} mongo.user.insert(update_user) text = _('已更新全域白名單 ✅')
def add_white(bot, update, args): i18n(update).loads.install(True) if len(args) == 0: try: update.message.delete() except BaseException: pass return admins = bot.get_chat_member(update.message.chat.id, update.message.from_user.id) if is_admin(bot, update) == False: try: update.message.delete() except BaseException: pass text = '此指令只允許管理員操作。' update.message.reply_text(text) return mongo = db_tools.use_mongo() if len(args) > 1: update.message.reply_text(_('傳入過多參數。')) return try: uid = int(args[0]) except BaseException: update.message.reply_html(_(f'UID <code>{args[0]}</code> 解析錯誤 ')) return if uid > 9999999999: update.message.reply_text(_('傳入怪怪的 UID 參數。')) return query_group = mongo.group.find_one({'chat.id': update.message.chat.id}) if query_group: group = db_parse.group() group.parse(query_group) if group.white_participate: if uid in group.white_participate: text = _(f'<code>{uid}</code> 已在群組白名單內') update.message.reply_html(text) else: mongo.group.update_one( {'chat.id': group.id}, {'$addToSet': { 'chat.white_participate': uid }}, upsert=True) text = _('已更新白名單 ✅') update.message.reply_text(text) else: text = _('似乎發生了點問題...?\n') + \ _('請先使用 <code>!hex config</code> 設定群組試試?') update.message.reply_html(text)
def inherit_excalibur(bot, update, inherit_from: db_parse.user): ''' inherit_from: db_parse.user inherit_to: user obj 轉傳訊息 ''' mongo = db_tools.use_mongo() query_user = mongo.user.find_one({'chat.id': update.message.from_user.id}) if query_user is None: user_update = {'chat': update.message.from_userto_dict()} mongo.user.insert(user_update) query_user = mongo.user.find_one( {'chat.id': update.message.from_user.id}) user_ = db_parse.user() user_.parse(query_user) channel = config.getint('log', 'evidence') try: evidence = update.message.forward(channel).message_id except BaseException: evidence = 2 current = inherit_from.current_raw update_user = {'inherit': { 'id': inherit_from.id, 'chat': { 'id': update.message.chat.id }, 'evidence': inherit_from.current.evidence }} current['evidence'] = evidence current.update(update_user) logger.info(current) if user_.current: # 新增 current, 舊的移動到 history array user_update = {'$push': {'history': user_.current_raw}, '$set': {'current': current}} mongo.user.find_one_and_update( {'chat.id': update.message.from_user.id}, user_update) elif user_.current is None: # 不是拉 警察這是我第一次拉 # : 欸 我也是第一次開罰單啊 Q_Q # 辣我可以順便要你的電話嘛? OS: 好 好...好可愛 # : Q_Q 不要投訴我啦 user_update = {'$set': {'current': current}} mongo.user.find_one_and_update( {'chat.id': update.message.from_user.id}, user_update)
def hint(bot, update): query = update.callback_query i18n(query).loads.install(True) mongo = db_tools.use_mongo() callback = callabck_parse.callback_parse(query.data) if callback.qact in ['groupconfig', 'guide']: if callback.qdata in emojitags().emoji_dict.keys(): answer = emojitags().emoji_dict[callback.qdata]['hint'] elif callback.qdata in generate.groupconfig_dict(1).keys(): answer = generate.groupconfig_dict(1)[callback.qdata]['hint'] query.answer(_('{answer}'.format(answer=answer)), show_alert=True)
def image_del(bot, update): if sage.michael(update.message.from_user.id) or sage.lucifer( update.message.from_user.id): mongo = db_tools.use_mongo() file = bytes(update.message.reply_to_message.photo[-1].get_file(). download_as_bytearray()) bio = io.BytesIO(file) i = imagehash.hashing(bio) hashing = i.phash() update_xmedia = { '$set': { 'photo.hash': hashing, 'photo.is_white': False } } mongo.xmedia.find_one_and_update({'photo.hash': hashing}, update_xmedia) update.message.reply_text('Done')
def admins(bot, update): mongo = db_tools.use_mongo() query_group = mongo.group.find_one({'chat.id': update.message.chat.id}) if query_group == []: update.message.reply_text(_('請先執行設定,請在群組內發送 <code>!hex config</code>')) return group = db_parse.group() group.parse(query_group) if group.config.admin: admin_ = admins_text(bot, update) update.message.reply_html(admin_) if Filters.reply(update.message): text = '#report\n' + info(bot, update, gettext=True).result() sent = bot.forward_message( config.getint('admin', 'elf'), update.message.chat.id, update.message.reply_to_message.message_id) keyboard = quickban(bot, update, sent.message_id) bot.send_message(config.getint('admin', 'elf'), text, reply_to_message_id=sent.message_id, reply_markup=keyboard, parse_mode='html')
def image(bot, update): if is_sage(update.message.from_user.id) != True: return if Filters.photo(update.message.reply_to_message) != True: return mongo = db_tools.use_mongo() file = bytes(update.message.reply_to_message.photo[-1].get_file(). download_as_bytearray()) bio = io.BytesIO(file) i = imagehash.hashing(bio) hashing = i.phash() middle = i.indexing() nsfw = nsfw_detect(file) query_xmedia = list( mongo.xmedia.find( {'photo.indexing': { '$gte': middle - 10, '$lte': middle + 10 }})) hash_media = '' hash_list = [] for x in query_xmedia[-5:]: media = db_parse.media() media.parse(x) hash_list.append(media.hash) percent = i.plooks_like(hash_list) for y in percent: hash_media += f'<code>{y.hash}</code> - <code>{y.score}%</code>\n' text = f'hash:<code>{i.phash()}</code>\n' \ f'NSFW Score:<code>{round(nsfw.score, 4)}</code>\n' \ '==Compare==\n' \ f'{hash_media}' update.message.reply_html(text)
def new_chat_members(bot, update): i18n(update).loads.install(True) mongo = db_tools.use_mongo() redis = db_tools.use_redis() # bot got invite if len(update.message.new_chat_members ) == 1 and update.message.new_chat_members[0].id == bot.id: # 處理紀錄 if update.message.chat.type == 'group': update.message.reply_text(_('多比只為住在大房子(supergroup)的主人服務')).result() bot.leave_chat(update.message.chat.id) return from_user = update.message.from_user count = bot.get_chat_members_count(update.message.chat.id) tmp = '<b>Invited</b>\n' \ f'Group Name: <code>{escape(update.message.chat.title)}</code> \n' \ f'Group ID: <code>{update.message.chat.id}</code> \n' \ f'Group Members Counts: {count}\n\n' \ f'<b>Invited By</b>\n' \ f'Name: {from_user.mention_html()}\n' \ f'Username: @{from_user.username}\n' \ f'UID: <code>{from_user.id}</code>\n' \ f'lang_code: <code>{from_user.language_code}</code>' if str(from_user.id).encode() in redis.lrange('ban_cache', 0, -1): tmp = '<b>已退出></b>\n' + tmp bot.send_message(config.getint('log', 'invitelog'), tmp, parse_mode='html') bot.leave_chat(update.message.chat.id) return keyboard = [[ InlineKeyboardButton( '報警', callback_data=f'bot leave {update.message.chat.id}' ), # leave group InlineKeyboardButton( '舔舔', callback_data=f'bot pass {update.message.chat.id}') ]] # keep in group keyboard = InlineKeyboardMarkup(keyboard) bot.send_message(config.getint('log', 'invitelog'), tmp, parse_mode='html', reply_markup=keyboard) # 安裝指南 guide(bot, update) # 記錄低逼 group = { 'chat': { 'title': f'{update.message.chat.title}', 'id': update.message.chat.id, 'config': { 'sub_ban_list': ['👶'], 'ml_nsfw': False, 'lang_code': None, 'admins': True } } } # 重新邀請會導致group資料洗掉ㄛ mongo.group.find_one_and_update({'chat.id': update.message.chat_id}, {'$set': group}, upsert=True) else: ''' new chat member flow - 檢查白名單 & 群組白名單 - 檢查紀錄 - 檢查名稱 - ads, halal name - kick, return - sent to abyss channel and record ''' for new_member in update.message.new_chat_members: border_keeper = gatejieitai( bot, update, (update.message.chat.id, new_member.id)) if border_keeper: if border_keeper.current.evidence: evidence = border_keeper.current.evidence else: evidence = 2 text = _('名稱:{fullname}\n' 'UID:<code>{user_id}</code>\n' '證據:https://t.me/hexevidence/{evidence}\n' '標籤:<code>{tags}</code>\n').format( fullname=new_member.mention_html(), user_id=new_member.id, evidence=evidence, tags=border_keeper.current.tags_text) if border_keeper.current.reason: reason = border_keeper.current.reason else: reason = border_keeper.current.tags_text if border_keeper.current.until == 0: text += _(banyourwords.forever.format(reason=reason)) else: text += _( banyourwords.temp.format( reason=reason, date=border_keeper.current.date_text)) text += _('\n處刑人:<code>{uid}</code>\n' '有任何問題請至 @hexjudge 詢問').format( uid=border_keeper.current.opid) try: update.message.delete() except BaseException: pass try: bot.restrict_chat_member(update.message.chat.id, new_member.id) except BadRequest as e: if e.message == 'Not enough rights to restrict/unrestrict chat member': text = _('⚠️為bot正常運作,請給予admin權限⚠️\n') + \ text + \ _('\n⚠️為bot正常運作,請給予admin權限⚠️') bot.send_message(update.message.chat.id, text, parse_mode='html') else: try: sent = bot.send_message(update.message.chat.id, text, parse_mode='html') except BaseException: pass time.sleep(15) try: bot.kick_chat_member(update.message.chat.id, new_member.id) except BaseException: pass bot.delete_message(update.message.chat.id, sent.result().message_id) else: checker(bot, update, new_member) from_user = update.message.from_user tmp = '<b>New</b>\n' \ f'Group ID:<code>{update.message.chat_id}</code>\n' \ f'Group Name:{escape(update.message.chat.title)}\n' \ f'Group Username:{f"@{update.message.chat.username}" if update.message.chat.username else None}\n' \ f'Name:{new_member.mention_html()}\n' \ f'Username:@{new_member.username}\n' \ f'UID:<code>{new_member.id}</code>\n' \ f'lang_code:<code>{new_member.language_code}</code>\n' \ f'Profile Pic:{profile_pic(new_member)}\n' \ '=======================\n' keyboard = [[ InlineKeyboardButton( '炸他全家', callback_data= f'user bypass {update.message.chat_id}:-{new_member.id}' ), # kick new member InlineKeyboardButton( '他還只是個孩子啊', callback_data= f'user bypass {update.message.chat.id}:+{new_member.id}') ]] # keep new member if from_user.id != new_member.id: tmp += '<b>Invite By</b>\n' \ f'Name:{from_user.mention_html()}\n' \ f'Username:@{from_user.username}\n' \ f'UID:<code>{from_user.id}</code>\n' \ f'lang_code:<code>{from_user.language_code}</code>\n' \ f'Profile Pic:{profile_pic(from_user)}\n' \ '=======================\n' keyboard = [ [ InlineKeyboardButton( "掐死被邀人", callback_data= f'user bypass {update.message.chat.id}:+{from_user.id}:-{new_member.id}' ), # kick from_user group InlineKeyboardButton( "掐死邀請人", callback_data= f'user bypass {update.message.chat.id}:-{from_user.id}:+{new_member.id}' ) ], # kick new_member group [ InlineKeyboardButton( "先放過", callback_data= f'user bypass {update.message.chat.id}:+{from_user.id}:+{new_member.id}' ), # keep both InlineKeyboardButton( "殉情", callback_data= f'user bypass {update.message.chat.id}:-{from_user.id}:-{new_member.id}' ) ] ] # kick both] # update participate group query_participate = mongo.user.find_one({'chat.id': new_member.id}) part = db_parse.user() part.parse(query_participate) if part.participate: participate = part.participate if update.message.chat.id not in participate: participate.append(update.message.chat.id) else: participate = [update.message.chat_id] update_user = {'$set': {'chat': {**new_member.to_dict()}}} update_user['$set']['chat'].update({'participate': participate}) mongo.user.find_one_and_update({'chat.id': new_member.id}, update_user, upsert=True) keyboard = InlineKeyboardMarkup(keyboard) bot.send_message(config.getint('log', 'namecheck'), tmp, parse_mode='html', reply_markup=keyboard)
def checker(bot, update, new_member): # halal 合併 /name locales.i18n(update).loads.install(True) mongo = db_tools.use_mongo() user = db_parse.user() group = db_parse.group() query_user = mongo.user.find_one({'chat.id': new_member.id}) query_group = mongo.group.find_one({'chat.id': update.message.chat.id}) user.parse(query_user) group.parse(query_group) for check in checker_list: do_check = check() checker_result, checker_name, checker_match = do_check.detect( new_member.full_name.lower()) if group.config is None: # 無心市政 # 城市不築 敗事有瑜 return tags_result = bool( set(group.config.sub_ban_list).intersection(to_emoji( do_check.tags))) if checker_result and tags_result: # halal 先上標籤啦 if checker_name in ['halal_arabic', 'halal_cyrillic']: excalibur(bot, update, new_member.id, tags=['halal'], opid=bot.id, reason='花瓜 呱呱呱') try: update.message.delete() except BaseException: pass try: bot.restrict_chat_member(update.message.chat_id, new_member.id, until_date=None, can_send_messages=None, can_send_media_messages=None, can_send_other_messages=None) except BadRequest: text = _('海克斯希貝兒先知系統偵測到一個<code>心靈指數過高用戶</code>,請給予相應權限作出處理。\n') + \ _(f'名稱:{new_member.mention_html()}\n') + \ _(f'UID:<code>{new_member.id}</code>\n') + \ _(f'偵查:<code>{checker_name}</code>') update.message.reply_text(text, parse_mode='html') break else: ''' Name: 虎虎 UID: 123123 因為 {checker name} 導致 心靈指數 指數過高,主宰者 切換至 摧毀分解 模式。 若有誤判請至 @hexjudge 報告 希貝兒先知系統 存在問題 案件追蹤 ID:update_id ''' record_msg = f'Name:{new_member.mention_html()}\n' \ f'UID:<code>{new_member.id}</code>\n' \ f'Checker:{checker_name}\n' \ f'Group Name:<code>{update.message.chat.title}</code>\n' \ f'Group ID:<code>{update.message.chat.id}</code>\n' \ f'Group Username:{"@{update.message.chat.username}" if update.message.chat.username else None}\n' \ f'#{checker_name} #tracker_{update.update_id}' bot.send_message(config.getint('log', 'abyss'), record_msg, parse_mode='html') tmp = _(f'名稱:{new_member.mention_html()}\n') + \ _(f'UID:<code>{new_member.id}</code>\n') + \ _(f'因為 <code>{checker_name}</code> 導致<code>心靈指數</code>過高,<code>主宰者</code>切換至摧毀分解模式。\n') + \ _(f'若有誤判請至 @hexjudge 報告海克斯希貝兒先知系統存在問題\n') + \ _(f'案件追蹤:#tracker_{update.update_id}') warn_msg = update.message.reply_text(tmp, parse_mode='html') time.sleep(10) bot.kick_chat_member(update.message.chat_id, new_member.id) try: bot.delete_message(update.message.chat_id, warn_msg.result().message_id) except BadRequest: pass return True return False
from plugin import db_parse, db_tools mongo = db_tools.use_mongo() redis = db_tools.use_redis() def refresh(): query_sticker = mongo.sticker.find() redis.delete('sticker_cache') for query in query_sticker: sticker = db_parse.sticker() sticker.parse(query) if sticker.set_name: redis.lpush('sticker_cache', sticker.set_name) def checker(bot, update, set_name=None): stickers = redis.lrange('sticker_cache', 0, -1) d = set_name.encode() if set_name and set_name.encode() in stickers: return True else: False
def homicide(bot, update, target: 'input uid with int'): ''' 列舉 UID 所參與的群組,然後幹他 Here's Johnny ~ https://media.giphy.com/media/RoajqIorBfSE/giphy.gif ''' i18n(update).loads.install(True) mongo = db_tools.use_mongo() user = db_parse.user() query_user = mongo.user.find_one({'chat.id': target}) if query_user == []: logger.debug('query user not found') return user.parse(query_user) if user.participate is None or user.participate == []: return for group in user.participate: if gatejieitai(bot, update, specfic=(group, target)): update.message.chat.id = group try: bot.kick_chat_member(group, user.id, until_date=user.current.until) except BadRequest as e: if e.message == 'Not enough rights to restrict/unrestrict chat member': text = _('⚠️ 權限不足而無法處理 ⚠️\n') + \ _(f'名字:{user.mention_html}\n') + \ _(f'UID:{user.id}\n') + \ _(f'證據:https://t.me/hexevidence{user.current.evidence}\n') + \ _(f'標籤:{user.current.tags_text}\n') if user.current.until_date.year < 2019: if user.current.reason: text += _( banyourwords.banyourwords.forever.format( reason=user.current.reason)) else: text += _( banyourwords.banyourwords.forever.format( reason=user.current.tags_text)) else: if user.current.reason: text += _( banyourwords.banyourwords.temp.format( reason=user.current.reason)) else: text += _( banyourwords.banyourwords.temp.format( reason=user.current.tags_text)) text += _(f'處刑人:{user.current.opid}\n') + \ _(f'有任何問題請至 @hexjudge 詢問') sent = bot.send_message(group, text, parse_mode='html').result() time.sleep(10) bot.delete_message(group, sent.message_id) elif e.message == 'User is an administrator of the chat': text = _('⚠️ 管理員被標記 ⚠️\n') + \ _(f'名字:{user.mention_html}\n') + \ _(f'UID:{user.id}\n') + \ _(f'證據:https://t.me/hexevidence{user.current.evidence}\n') + \ _(f'標籤:{user.current.tags_text}\n') if user.current.until_date.year < 2019: if user.current.reason: text += _( banyourwords.banyourwords.forever.format( reason=user.current.reason)) else: text += _( banyourwords.banyourwords.forever.format( reason=user.current.tags_text)) else: if user.current.reason: text += _( banyourwords.banyourwords.temp.format( reason=user.current.reason)) else: text += _( banyourwords.banyourwords.temp.format( reason=user.current.tags_text)) text += _(f'處刑人:{user.current.opid}\n') + \ _(f'有任何問題請至 @hexjudge 詢問') update_white = { '$addToSet': { 'chat.white_participate': target } } mongo.group.up({'chat.id': group}, update_white) sage.refresh() else: threading.Thread(target=extinguish, name=f'{group}_del_msg', args=[bot, update, (group, target)]).start() text = _(f'名字:{user.mention_html}\n') + \ _(f'UID:{user.id}\n') + \ _(f'證據:https://t.me/hexevidence{user.current.evidence}\n') + \ _(f'標籤:{user.current.tags_text}\n') if user.current.reason: reason = user.current.reason else: reason = user.current.tags_text if user.current.until_date.year < 2019: text += _( banyourwords.banyourwords.forever.format( reason=reason)) else: text += _( banyourwords.banyourwords.temp.format( reason=reason, date=user.current.until_text)) text += _(f'\n處刑人:{user.current.opid}\n') + \ _(f'有任何問題請至 @hexjudge 詢問') sent = bot.send_message(group, text, parse_mode='html').result() user_update = { '$pull': { 'chat.participate': group }, '$push': { 'chat.banned_participate': group } } mongo.user.find_one_and_update({'chat.id': user.id}, user_update) time.sleep(10) bot.delete_message(group, sent.message_id)
def extend_links(bot, update, inherit, cmd=None): # tinyurl, t.cn, bit.ly return False locales.i18n(update).loads.install(True) pattern = r'(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)(tinyurl\.com|bit\.ly|t\.cn)(\/[a-z0-9]+)' result = re.findall(pattern, unescape(update.message.text_html), re.IGNORECASE) if len(result) == 0: return False extract_result = checker_result() extract_result.tags = [] extract_result.name = '' for x in result: url = ''.join(x) # binance_shortcut.ico req = requests.get(url, allow_redirects=False) try: real_url = req.headers['Location'] except Exception as e: logger.exception(e) ## Do All Checker ## for checker in check_list: result_ = checker(bot, update, real_url) if result_.name: extract_result.name += result_.name extract_result.tags.extend(result_.tags) else: return ## Do All Checker ## if sage.in_shield(update.message.from_user.id): return if is_participate_white(bot, update): return if is_admin(bot, update): return if extract_result.tags == []: logger.info('return with null tags') return day = druation(list(dict.fromkeys(extract_result.tags))) tags = list(dict.fromkeys(extract_result.tags)) mongo = db_tools.use_mongo() query_group = mongo.group.find_one({'chat.id': update.message.chat.id}) if query_group: group = db_parse.group() group.parse(query_group) else: return True if bool(set(group.config.sub_ban_list).intersection(list(to_emoji(tags)))): pass else: return evidence = 2 try: fwd = update.message.forward(config.getint('log', 'evidence')) except BadRequest as e: pass else: evidence = fwd.message_id if day == 0: until = 0 else: until = (datetime.now(taiwan_country) + timedelta(days=day)).timestamp() excalibur(bot, update, update.message.from_user.id, tags, bot.id, until=until, reason=f'hex auto.{extract_result.name}', evidence=evidence) right = False try: update.message.delete() except BaseException: right = True try: bot.restrict_chat_member(update.message.chat.id, update.message.from_user.id) except BaseException: right = True text = _('偵測到 <code>{checker}</code> 垃圾訊息\n').format( checker=extract_result.name) if right: text += _('⚠️權限不足無法操作⚠️\n') if extract_result.tags: text += _('依照契約內容已吞噬 <code>Sammer</code>\n') text += _('名字:{full_name}\n' + 'UID:<code>{user_id}</code>\n' + '標籤:<code>{tags}</code>').format( full_name=update.message.from_user.mention_html(), user_id=update.message.from_user.id, tags=', '.join(tags)) sent = update.message.reply_html(text).result() time.sleep(10) sent.delete() homicide(bot, update, update.message.from_user.id)
def excalibur( bot, update, uid, tags, opid, date=None, until=0, reason=None, evidence=2, user=None, reply=False): i18n(update).loads.install(True) mongo = db_tools.use_mongo() redis = db_tools.use_redis() query_user = mongo.user.find_one({'chat.id': uid}) parse = parser(uid, tags, opid, date=date, until=until, reason=reason, evidence=evidence, user=user) if query_user: user_ = db_parse.user() user_.parse(query_user) if user_.current: # 新增 current, 舊的移動到 history array user_update = {'$push': {'history': user_.current_raw}, '$set': {'current': parse}} mongo.user.find_one_and_update({'chat.id': uid}, user_update) elif user_.current is None: # 不是拉 警察這是我第一次拉 # : 欸 我也是第一次開罰單啊 Q_Q # 辣我可以順便要你的電話嘛? OS: 好 好...好可愛 # : Q_Q 不要投訴我啦 user_update = {'$set': {'current': parse}} mongo.user.find_one_and_update({'chat.id': uid}, user_update) else: if user: user_update = {'chat': user.to_dict(), 'current': parse} mongo.user.insert(user_update) else: user_update = {'chat': {'id': uid}, 'current': parse} mongo.user.insert(user_update) ban_cache = redis.lrange('ban_cache', 0, -1) if str(uid).encode() not in ban_cache: redis.lpush('ban_cache', uid) if query_user: return announce( uid, tags, opid, date=None, until=until, reason=reason, evidence=evidence, query_user=user_, reply=False) else: return announce(uid, tags, opid, date=None, until=until, reason=reason, evidence=evidence)
def unban(bot, update): i18n(update).loads.install(True) # !hex unban u=123 r=噗噗噗 if sage.michael(update.message.from_user.id) == False: update.message.reply_text('權限不足啦 🌚') return if sage.lucifer(update.message.from_user.id) == False: update.message.reply_text('權限不足啦 🌚') return args = update.message.text.split() if len(args) == 2: update.message.reply_text(_('缺少參數')) return reason = search('r={:S}', update.message.text) uid = search('u={:d}', update.message.text) if uid is None: update.message.reply_html(_('缺少 <code>u=</code> 參數')) return else: uid = uid[0] if reason is None: update.message.reply_html(_('缺少 <code>r=</code> 參數')) return else: reason = reason[0] mongo = db_tools.use_mongo() redis = db_tools.use_redis() query_user = mongo.user.find_one({'chat.id': uid}) if query_user is None: update.message.reply_html(_('找不到這個人,失蹤了!!')) return user = db_parse.user() user.parse(query_user) if user.current is None: update.message.reply_html(_('這人沒有被封鎖過啊')) return user.current_raw['unban'] = reason update_user = { '$unset': { 'current': '' }, '$addToSet': { 'history': user.current_raw } } mongo.user.find_one_and_update({'chat.id': uid}, update_user) redis.lrem('ban_cache', uid, 0) if user.banned_participate is None or user.banned_participate == []: update.message.reply_text('解除封鎖完成。') return groups = '' for ban in user.banned_participate: try: user_ = bot.get_chat_member(ban, uid) except BaseException: groups += _('解封失敗\n') + \ f'{ban}' else: if user_.status == 'kicked': try: bot.unban_chat_member(ban, uid) except BaseException: groups += _('解封失敗\n') + \ f'{ban}' else: query_group = mongo.group.find_one({'chat.id': ban}) if query_group: group = db_parse.group() group.parse(query_group) groups += f'<code>{group.title}</code>\n' + \ f'<code>{ban}</code>\n' + \ f'{"="*10}\n' else: groups += f'<code>{ban}</code>' update_user = {'$pull': {'chat.banned_participate': ban}} mongo.user.find_one_and_update({'chat.id': uid}, update_user) update.message.reply_html('[解封完成]\n' + groups)
def __init__(self, update): self.mongo = db_tools.use_mongo() self.update = update self.lang = i18n_tool().lang self.loads = self.loads_()
def gatejieitai(bot, update, specfic=False): # compare from_user and chat.id and tags if banned in group # return True if need action mongo = db_tools.use_mongo() redis = db_tools.use_redis() user = db_parse.user() group = db_parse.group() # check cache query_redis = redis.lrange('ban_cache', 0, -1) query_white = redis.lrange('white_cache', 0, -1) if specfic: specfic_chat, specfic_id = specfic else: specfic_chat, specfic_id = update.message.chat.id, update.message.from_user.id if str(specfic_id).encode() not in query_redis: logger.debug(f'{specfic_id} not in redis cache') return False if str(specfic_id).encode() in query_white: logger.debug(f'{specfic_id} in white cache') return False if sage.is_sage(specfic_id): logger.debug(f'{specfic_id} in sage') return False query_group_white = redis.lrange(f'white:{str(specfic_chat)}', 0, -1) if str(specfic_id).encode() in query_group_white: logger.debug(f'{specfic_id} in group white cache') return False else: user_query = mongo.user.find_one( {'chat.id': specfic_id}) group_query = mongo.group.find_one({'chat.id': specfic_chat}) user.parse(user_query) group.parse(group_query) if user.current is None: return False if group_query is None: return False date = datetime.fromtimestamp( user.current.until).astimezone(taiwan_country) now = datetime.now(taiwan_country) l = user.current.until - now.timestamp() if user.current.until - now.timestamp() > 0: # kick yout ass if group.config.sub_ban_list: # 比較兩者 check = bool(set(group.config.sub_ban_list).intersection( user.current.tags_list)) if check: return user else: # 沒有設定清單 return False else: # bang for ever if date.year == 1970: if group.config and group.config.sub_ban_list: check = bool(set(group.config.sub_ban_list).intersection( user.current.tags_list)) if check: return user # punishiment finished if user.current.until - now.timestamp() <= 0 and user.current.until != 0: logger.info('punishiment fin') mongo.user.find_one_and_update( {'chat.id': specfic_id}, {'$set': {'chat.banned_participate': []}} ) return False
def groupconfig_callback(bot, update): query = update.callback_query i18n(update).loads.install(True) mongo = db_tools.use_mongo() callback = callabck_parse.callback_parse(query.data) query_group = mongo.group.find_one({'chat.id': query.message.chat.id}) group = db_parse.group() group.parse(query_group) if sage.lucifer(query.from_user.id) or is_admin( bot, update, (query.message.chat.id, query.from_user.id)): pass else: text = '你又不是管理員 😘' query.answer(text, show_alert=True) return if group.config is None: return if callback.qact == 'keyboard' and callback.qdata == 'close': text = _('<code>[設定完成]</code>\n\n') + \ _(f'<code>{escape(query.message.chat.title)}</code>\n') + \ _('📋 已訂閱黑名單列表:\n') emoji_list = emojitags().emoji_dict sub = '' plugin_ = '' for emoji in emoji_list: if emoji_list[emoji]['emoji'][0] in group.config.sub_ban_list: sub += '{title}\n'.format(title=_(emoji_list[emoji]['title'])) text += f'<pre>{sub}</pre>' for groupconfig_mcro in group.config_list_k: if groupconfig_mcro: plugin_ += '{title}\n'.format(title=generate.groupconfig_dict( 1)[groupconfig_mcro]['title']) if plugin_: text += _('⚙️ 已啟動附加功能:\n') + f'<pre>{plugin_}</pre>' query.edit_message_text(text=text, parse_mode='html') elif callback.qact == 'keyboard': if callback.qdata == '0': text = f'<code>{escape(query.message.chat.title)}</code>\n' + \ _('📋 訂閱黑名單列表\n') + \ _('本清單預設開啟 "兒童色情內容" \n') + \ _('✅ - 開啟訂閱\n') + \ _('❌ - 關閉訂閱') keyboard = generate.inline_groupconfig(bot, update, 0) query.edit_message_text(text=text, reply_markup=keyboard, parse_mode='html') elif callback.qdata == '1': text = f'<code>{escape(query.message.chat.title)}</code>\n' + \ _('⚙️ 附加功能設定\n') + \ _('✅ - 開啟訂閱\n') + \ _('❌ - 關閉訂閱') keyboard = generate.inline_groupconfig(bot, update, 1) query.edit_message_text(text=text, reply_markup=keyboard, parse_mode='html') elif callback.qdata == '2': text = f'<code>{escape(query.message.chat.title)}</code>\n' + \ '🌐 語言設定/Language Settings\n' + \ _('✅ - Choosen\n') keyboard = generate.inline_groupconfig(bot, update, page=2) query.edit_message_text(text=text, reply_markup=keyboard, parse_mode='html') elif callback.qact == 'sub': # group.config.sub_ban_list click = to_emoji([callback.qdata]) sub_total = len(emojitags().emoji_dict.keys()) - 1 if click not in group.config.sub_ban_list and callback.qdata != 'spam': group.config.sub_ban_list.extend(click) if sub_total == len(group.config.sub_ban_list): group.config.sub_ban_list.append('💩') mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, { '$set': { 'chat.config.sub_ban_list': group.config.sub_ban_list } }) elif click in group.config.sub_ban_list and callback.qdata != 'spam': group.config.sub_ban_list.remove(click[0]) if sub_total == len(group.config.sub_ban_list): group.config.sub_ban_list.remove('💩') mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, { '$set': { 'chat.config.sub_ban_list': group.config.sub_ban_list } }) if callback.qdata == 'spam': if sub_total > len(group.config.sub_ban_list): group.config.sub_ban_list = to_emoji( list(emojitags().emoji_dict.keys())) mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, { '$set': { 'chat.config.sub_ban_list': list(group.config.sub_ban_list) } }) else: group.config.sub_ban_list = [] mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, { '$set': { 'chat.config.sub_ban_list': group.config.sub_ban_list } }) keyboard = generate.inline_groupconfig(bot, update, 0) query.edit_message_reply_markup(reply_markup=keyboard) query.answer('Done.') elif callback.qact == 'set': # group.config.ml_nsfw if callback.qdata in group.config_list.keys(): if group.config_list[callback.qdata]: mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, {'$set': { f'chat.config.{callback.qdata}': False }}, upsert=True) else: mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, {'$set': { f'chat.config.{callback.qdata}': True }}, upsert=True) else: if callback.qdata == 'all': group_config = query_group['chat']['config'].copy() for settings in generate.groupconfig_dict(1): group_config[settings] = True if group_config == query_group['chat']['config']: query.answer('>:(') return mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, {'$set': { f'chat.config': group_config }}, upsert=True) else: mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, {'$set': { f'chat.config.{callback.qdata}': True }}, upsert=True) keyboard = generate.inline_groupconfig(bot, update, 1) try: query.edit_message_reply_markup(reply_markup=keyboard) query.answer('Done.') except Exception as e: logger.warning(e) elif callback.qact == 'langset': mongo.group.find_one_and_update( {'chat.id': query.message.chat.id}, {'$set': { 'chat.config.lang_code': callback.qdata }}) keyboard = generate.inline_groupconfig(bot, update, 2) try: query.edit_message_reply_markup(reply_markup=keyboard) query.answer('Done.') except Exception as e: logger.warning(e)