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 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 bang(bot, update): ''' - kick - forward - delete - send report ''' i18n(update).loads.install(True) try: update.message.delete() except BaseException: pass # right check if sage.is_sage(update.message.from_user.id): pass else: if is_admin(bot, update): pass else: return sent = bot.forward_message(config.getint('admin', 'elf'), update.message.chat.id, update.message.reply_to_message.message_id) try: bot.delete_message(update.message.chat.id, update.message.reply_to_message.message_id) except BaseException: pass try: bot.kick_chat_member(update.message.chat_id, update.message.reply_to_message.from_user.id) except BadRequest as e: if e.message == 'User is an administrator of the chat': update.message.reply_text(_( f'目標 {update.message.reply_to_message.from_user.mention_html()} 為管理員。' ), parse_mode='html') elif e.message == 'Not enough rights to restrict/unrestrict chat member': update.message.reply_text(_('指令處理失敗\n原因:<code>權限不足</code>'), parse_mode='html') else: update.message.reply_text( _(f'指令處理失敗\n原因:<code>{escape(e.message)}</code>'), parse_mode='html') # report to elf 鍵盤 text = '#banglog #report\n' + info(bot, update, gettext=True).result() keyboard = quickban(bot, update, update.message.message_id) bot.send_message(config.getint('admin', 'elf'), text, reply_markup=keyboard, reply_to_message_id=sent.message_id, parse_mode='html')
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 banstat_chat(bot, update): i18n(update).loads.install(True) if Filters.forwarded(update.message.reply_to_message): if update.message.reply_to_message.forward_from_chat: query = mongo.user.find_one( {'chat.id': update.message.reply_to_message.forward_from_chat.id}) if query: user = db_parse.user() user.parse(query) text = _(f'頻道名稱:<code>{update.message.reply_to_message.forward_from_chat.title}</code>\n') + \ _(f'UID:<code>{update.message.reply_to_message.forward_from_chat.id}</code>\n') + \ _(f'標籤:{user.current.tags}\n') + \ _(f'證據:https://t.me/hexevidence/{user.current.evidence}\n') + \ _(f'封鎖日:<code>{user.current.date_text}</code>\n') + \ _(f'封鎖到:<code>{user.current.until_text}</code>') if sage.is_sage( update.message.from_user.id) or sage.is_sage( update.message.reply_to_message.from_user.id): excuse = mongo.user.find_one( {'chat.id': user.current.opid}) execser = db_parse.user() execser.parse(excuse) text = text + \ _(f'\n處刑人: <a href="tg://user?id={user.current.opid}">{execser.fullname}</a>') else: text = _(f'頻道名稱:<code>{update.message.reply_to_message.forward_from_chat.title}</code>\n') + \ _(f'UID:<code>{update.message.reply_to_message.forward_from_chat.id}</code>\n') + \ _(f'頻道未被封鎖') return text else: if update.message.reply_to_message.forward_from: update.message.from_user = update.message.reply_to_message.forward_from return banstat_user(bot, update) else: return _('找不到目標!\n可能來源訊息沒有連結到發送者帳號。') else: update.message.from_user = update.message.reply_to_message.from_user return banstat_user(bot, update)
def banstat_user_args(bot, update, args): i18n(update).loads.install(True) try: uid = int(args[0]) except ValueError as e: logger.warn(e) args = ' '.join(args) return _(f'<code>{args}</code> 啊...恩...啊...這..好像不是 UID') query = mongo.user.find_one({'chat.id': uid}) text = '' if query: user = db_parse.user() user.parse(query) if user.current is None: text = _(f'UID:<code>{uid}</code>\n') + \ _('並未被封鎖') return text text = '' if user.fullname: text += _(f'名字:<code>{user.fullname}</code>\n') text += _(f'UID:<code>{uid}</code>\n') + _(f'標籤:{user.current.tags}\n') + _( f'證據:https://t.me/hexevidence/{"2" if user.current.evidence == None else user.current.evidence}\n') if user.current.reason: text += _(f'說明:<code>{user.current.reason}</code>\n') text += _(f'封鎖日:<code>{user.current.date_text}</code>\n') + \ _(f'封鎖到:<code>{user.current.until_text}</code>\n') if sage.is_sage(update.message.from_user.id): execser = db_parse.user() excuse = mongo.user.find_one( {'chat.id': user.current.opid}) execser.parse(excuse) text = text + \ _(f'\n處刑人:{execser.mention_html}') return text else: text = _(f'UID:<code>{uid}</code>\n') + \ _('並未被封鎖') return text
def hexban_long(bot, update): i18n(update).loads.install(True) if sage.is_sage(update.message.from_user.id) == False: try: update.message.delete() except BaseException: return sent = update.message.reply_text('騷年,你渴望力量ㄇ?').result() time.sleep(5) sent.delete() return if sage.elf(update.message.from_user.id): update.message.reply_text(_('等級不夠 🌚')) return # !hex ban u=123 t=spam day = search('ban={:d}d', update.message.text) reason = search('r={:S}', update.message.text) tags = search('t={:S}', update.message.text) uid = search('u={:d}', update.message.text) now = datetime.now(taiwan_country) if tags is None: update.message.reply_html(_('缺少 <code>標籤</code> 參數。')) return elif uid is None: update.message.reply_html(_('缺少 <code>UID</code> 參數。')) return if uid: uid = uid[0] if tags: tags = tags[0].split(',') if 'spam' not in tags: tags.append('spam') for tag in tags: if tag not in emojitags().emoji_dict.keys(): text = _(f'找不到 <code>{tag}</code> 標籤') update.message.reply_html(text) return if day: if day[0] == 0: until = 0 else: until = int((now + timedelta(days=day[0])).timestamp()) else: day_ = druation(tags) if day_ == 0: until = 0 else: until = int((now + timedelta(days=day_)).timestamp()) if sage.in_shield(uid): if sage.is_sage(uid): text = '精靈保護 🌚' else: text = '白色恐怖ㄉ力量 🌝' update.message.reply_text(text) return until_text = datetime.fromtimestamp(until).astimezone(taiwan_country) opid = update.message.from_user.id tags_text = ', '.join(tags) evidence = 2 opid = update.message.from_user.id if reason: reason = reason[0] else: reason = tags_text query_user = mongo.user.find_one({'chat.id': uid}) excalibur(bot, update, uid=uid, tags=tags, opid=opid, until=until, reason=reason) text = '' if query_user: user = db_parse.user() user.parse(query_user) if user.fullname: if user.id < 0: text += _(f'頻道:<code>{user.fullname}</code>\n') else: text += _(f'名字:<code>{user.fullname}</code>\n') text += _(f'UID:<code>{uid}</code>\n') + \ _(f'標籤:<code>{tags_text}</code>\n') + \ _(f'證據:https://t.me/hexevidence/{evidence}\n') if until == 0: text += _(banyourwords.forever.format(reason=reason)) else: text += _(banyourwords.temp.format(reason=reason, date=until_text)) update.message.reply_html(text, web_page_preview=False)
def hexban_reply(bot, update): ''' !hex ban ads,scam !hex ban u=123 t=scam r=ㄏㄏ ''' i18n(update).loads.install(True) if sage.is_sage(update.message.from_user.id) == False: try: update.message.delete() except BaseException: return sent = update.message.reply_text('騷年,你渴望力量ㄇ?').result() time.sleep(5) sent.delete() if sage.elf(update.message.from_user.id): update.message.reply_text(_('等級不夠 🌚')) return args = update.message.text.split() if len(args) == 3: # !hex ban ads,scam tags = args[2].split(',') for tag in tags: if tag not in emojitags().emoji_dict.keys(): text = _(f'找不到 <code>{tag}</code> 標籤') update.message.reply_html(text) return if 'spam' not in tags: tags.append('spam') day = druation(tags) now = datetime.now(taiwan_country) if day == 0: until = 0 else: until = int((now + timedelta(days=day)).timestamp()) tags_text = ', '.join(tags) opid = update.message.from_user.id bang = [] if sage.in_shield( update.message.reply_to_message.from_user.id) == False: bang = [update.message.reply_to_message.from_user] if update.message.reply_to_message.forward_from: if sage.in_shield( update.message.reply_to_message.forward_from.id) == False: bang.append(update.message.reply_to_message.forward_from) if update.message.reply_to_message.forward_from_chat: if sage.in_shield( update.message.reply_to_message.forward_from_chat.id) == False: bang.append(update.message.reply_to_message.forward_from_chat) if bang: try: sent = bot.forward_message( config.getint( 'log', 'evidence'), update.message.reply_to_message.chat.id, update.message.reply_to_message.message_id) except BaseException: sent = None if sent: evidence = sent.message_id else: evidence = 2 else: text = '' if sage.in_shield(update.message.reply_to_message.from_user.id): if sage.is_sage(update.message.reply_to_message.from_user.id): text += _(f'<code>{update.message.reply_to_message.from_user.id}</code> 有精靈保護 🌚') else: text += _( f'<code>{update.message.reply_to_message.from_user.id}</code> 白色恐怖快逃R 🌚') if update.message.reply_to_message.forward_from: if sage.in_shield( update.message.reply_to_message.forward_from.id): if sage.is_sage( update.message.reply_to_message.forward_from.id): text += _( f'<code>{update.message.reply_to_message.forward_from.id}</code> 有精靈保護 🌚') else: text += _( f'<code>{update.message.reply_to_message.from_user.id}</code> 白色恐怖快逃R 🌚') if update.message.reply_to_message.forward_from_chat: if sage.in_shield( update.message.reply_to_message.forward_from_chat.id): if sage.is_sage( update.message.reply_to_message.forward_from_chat.id): text += _( f'<code>{update.message.reply_to_message.forward_from_chat.id}</code> 有精靈保護 🌚') else: text += _( f'<code>{update.message.reply_to_message.from_user.id}</code> 白色恐怖快逃R 🌚') update.message.reply_html(text) return if Filters.sticker(update.message.reply_to_message): if update.message.reply_to_message.sticker.set_name: update_sticker = { '$set': { 'sticker': { 'set_name': update.message.reply_to_message.sticker.set_name, 'tags': tags}, 'opid': update.message.from_user.id, 'reason': tags_text, 'evidence': evidence}} mongo.sticker.find_one_and_update( {'sticker.id': update.message.reply_to_message.sticker.file_id}, update_sticker, upsert=True) text = f'ID:<code>{update.message.reply_to_message.sticker.file_id}</code>\n' if update.message.reply_to_message.sticker.set_name: # https://t.me/addstickers/nichijou text += f'Set Name:https://t.me/addstickers/{update.message.reply_to_message.sticker.set_name}\n' text += _(f'標籤:<code>{tags_text}</code>') update.message.reply_html(text) sticker_judge.refresh() if Filters.photo(update.message.reply_to_message): 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() query_photo = mongo.xmedia.find_one({'photo.hash': hashing}) if query_photo: pass else: tmp_dict = {'photo': {'hash': hashing, 'tags': to_emoji(tags), 'indexing': i.indexing()}, 'evidence': evidence, 'opid': update.message.from_user.id, 'reason': tags_text} mongo.xmedia.insert_one(tmp_dict) text = f'hash:<code>{hashing}</code>\n' + \ _(f'標籤:<code>{tags_text}</code>\n') + \ _(f'標記:<code>{i.indexing()}</code>') update.message.reply_html(text) redis.lpush('photo_cache', hashing) for chat in bang: text = excalibur( bot, update, uid=chat.id, tags=tags, opid=opid, until=until, reason=tags_text, user=chat, evidence=evidence) update.message.reply_html(text, web_page_preview=False) update_user = {'$set': {'chat': chat.to_dict()}} mongo.user.find_one_and_update({'chat.id': chat.id}, update_user) homicide(bot, update, chat.id) # !hex ban t=ads r=臭 elif len(args) >= 4: day = search('ban={:d}d', update.message.text) reason = search('r={:S}', update.message.text) tags = search('t={:S}', update.message.text) uid = search('u={:d}', update.message.text) now = datetime.now(taiwan_country) if tags is None: text = f'缺少標籤參數。' update.message.reply_html(text) return else: tags = tags[0].split(',') if 'spam' not in tags: tags.append('spam') for tag in tags: if tag not in emojitags().emoji_dict.keys(): text = f'找不到 <code>{tag}</code> 標籤' update.message.reply_html(text) return if day: if day[0] == 0: until = 0 else: until = int((now + timedelta(days=day[0])).timestamp()) else: day_ = druation(tags) if day_ == 0: until = 0 else: until = int((now + timedelta(days=day_)).timestamp()) tags_text = ', '.join(tags) opid = update.message.from_user.id if reason: reason = reason[0] else: reason = tags_text if uid: uid = uid[0] try: sent = bot.forward_message( config.getint( 'log', 'evidence'), update.message.reply_to_message.chat.id, update.message.reply_to_message.message_id) except BaseException: sent = None if sent: evidence = sent.message_id else: evidence = 2 text = excalibur( bot, update, uid=uid, tags=tags, opid=opid, until=until, reason=reason, evidence=evidence) update.message.reply_html(text) return if sage.in_shield(update.message.reply_to_message.from_user.id): bang = [] else: bang = [update.message.reply_to_message.from_user] if update.message.reply_to_message.forward_from: if sage.in_shield( update.message.reply_to_message.forward_from.id) == False: bang.append(update.message.reply_to_message.forward_from) if update.message.reply_to_message.forward_from_chat: if sage.in_shield( update.message.reply_to_message.forward_from_chat.id) == False: bang.append(update.message.reply_to_message.forward_from_chat) if bang: try: sent = bot.forward_message( config.getint( 'log', 'evidence'), update.message.reply_to_message.chat.id, update.message.reply_to_message.message_id) except BaseException: sent = None if sent: evidence = sent.message_id else: evidence = 2 else: text = '' if update.message.reply_to_message.forward_from: if sage.is_sage( update.message.reply_to_message.forward_from.id): text += f'<code>{update.message.reply_to_message.forward_from.id}</code> 有精靈護體 🌚' else: text += f'<code>{update.message.reply_to_message.forward_from.id}</code> 白色恐怖快逃RRR 🌝' if update.message.reply_to_message.forward_from_chat: if sage.is_sage( update.message.reply_to_message.forward_from_chat): text += f'<code>{update.message.reply_to_message.forward_from_chat.id}</code> 有精靈護體 🌚' else: text += f'<code>{update.message.reply_to_message.forward_from_chat.id}</code> 白色恐怖快逃RRR 🌝' update.message.reply_html(text) if Filters.sticker(update.message.reply_to_message): if update.message.reply_to_message.sticker.set_name: update_sticker = { '$set': { 'sticker': { 'set_name': update.message.reply_to_message.sticker.set_name, 'tags': tags}, 'opid': update.message.from_user.id, 'reason': tags_text, 'evidence': evidence}} mongo.sticker.find_one_and_update( {'sticker.id': update.message.reply_to_message.sticker.file_id}, update_sticker, upsert=True) text = f'ID:<code>{update.message.reply_to_message.sticker.file_id}</code>\n' if update.message.reply_to_message.sticker.set_name: # https://t.me/addstickers/nichijou text += f'Set Name:https://t.me/addstickers/{update.message.reply_to_message.sticker.set_name}\n' text += _(f'標籤:<code>{tags_text}</code>') update.message.reply_html(text) sticker_judge.refresh() for chat in bang: update_user = {'$set': {'chat': chat.to_dict()}} mongo.user.find_one_and_update({'chat.id': chat.id}, update_user) text = excalibur( bot, update, uid=chat.id, opid=opid, until=until, reason=reason, tags=tags, user=chat, evidence=evidence) update.message.reply_html(text, web_page_preview=False)
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 banstat_user(bot, update): i18n(update).loads.install(True) query = mongo.user.find_one({'chat.id': update.message.from_user.id}) user = db_parse.user() user.parse(query) if user.current: text = _(f'名字:{update.message.from_user.mention_html()}\n') + \ _(f'UID:<code>{update.message.from_user.id}</code>\n') + \ _(f'標籤:{user.current.tags}\n') + \ _(f'證據:https://t.me/hexevidence/{user.current.evidence}\n') if user.current.reason: text += _(f'說明:<code>{user.current.reason}</code>\n') text += _(f'封鎖日:<code>{user.current.date_text}</code>\n') + \ _(f'封鎖到:<code>{user.current.until_text}</code>\n') elfs = update.message.from_user.id if update.message.reply_to_message: elfs = update.message.reply_to_message.from_user.id if sage.is_sage(elfs): logger.info(user.current.opid) excuse = mongo.user.find_one({'chat.id': user.current.opid}) execser = db_parse.user() execser.parse(excuse) text = text + \ _(f'\n處刑人: {execser.mention_html}') elif user.current is None: text = _(f'名字:{update.message.from_user.mention_html()}\n') + \ _(f'UID:<code>{update.message.from_user.id}</code>\n') + \ _('並未被封鎖') if Filters.reply( update.message) and Filters.sticker( update.message.reply_to_message): judge = sticker_judge.checker( bot, update, set_name=update.message.reply_to_message.sticker.set_name) text_sticker = '' if judge: query_stiker = mongo.sticker.find_one( {'sticker.set_name': update.message.reply_to_message.sticker.set_name}) sticker = db_parse.sticker() sticker.parse(query_stiker) text_sticker = _(f'貼圖:<code>{sticker.set_name}</code>\n') + \ _(f'標籤:<code>{sticker.tags_text}</code>') text += f'\n<code>{"="*23}</code>\n' + text_sticker else: text_sticker = _( f'貼圖:<code>{update.message.reply_to_message.sticker.set_name}</code>\n') + _('貼圖並未被封鎖!') text += f'\n<code>{"="*23}</code>\n' + text_sticker if Filters.reply( update.message) and Filters.photo( update.message.reply_to_message): 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() query_photo = mongo.xmedia.find_one({'photo.hash': hashing}) if query_photo: media = db_parse.media() media.parse(query_photo) text_photo = _(f'圖片標記:<code>{media.hash}</code>\n') + \ _(f'標籤:<code>{media.tags_text}</code>\n') + \ _(f'天數:<code>{druation(media.tags_list)}</code>') if sage.is_sage( update.message.from_user.id) or sage.is_sage( update.message.reply_to_message.from_user.id): # add excutor execser = db_parse.user() excuse = mongo.user.find_one( {'chat.id': media.opid}) execser.parse(excuse) text_photo += _(f'\n處刑人:{execser.mention_html}') text += f'\n<code>{"="*23}</code>\n' + text_photo else: text_photo = _('圖片並未被封鎖!') text += f'\n<code>{"="*23}</code>\n' + text_photo return text