def abuser(bot, update): if sage.lucifer(update.message.from_user.id) != True: update.message.reply_text('嘻嘻 等級不夠') return angel = {} user = db_parse.user() users = mongo.user.find({"current": {'$exists': True}, "current.date": {'$exists': True}}) for victim in users: user.parse(victim) if str(user.current.opid) not in angel.keys(): try: angel[f"{user.current.opid}"] = 1 except BaseException: raise else: try: angel[f"{user.current.opid}"] += 1 except BaseException: raise ranking = sorted(angel.items(), key=itemgetter(1)) ranking.reverse() text = '誰4濫權王??\n\n' for record in ranking: user = db_parse.user() op = mongo.user.find_one({'chat.id': int(record[0])}) user.parse(op) chart.add(user.fullname, record[1]) text += f'{user.mention_html} - {record[1]}\n' chart.render_to_png('pie.png') update.message.reply_html(text)
def new_member_check_ban(bot, update, new_member): i18n(update).loads.install(True) if gatejieitai( bot, update, specfic=( update.message.chat.id, new_member.id)): 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) try: update.message.delete() except BadRequest: pass if user.current.evidence is None: user.current.evidence = 2 text = _('名字:{fullname}\n' 'UID:{uid}\n' '證據:https://t.me/hexevidence/{evidence}\n' '標籤:{tags}\n' '因為 <code>{reason}</code>\n' '封鎖至 <code>{until}</code>\n' '處刑人:{execser}\n' '有任何問題請至 @hexjudge 詢問').format( fullname=new_member.mention_html(), uid=new_member.id, evidence=user.current.evidence, tags=to_string(user.current.tags), reason=user.current.reason, until=user.current.date_text, execser=user.current.opid) try: sent = bot.send_message( update.message.chat.id, text, parse_mode='html').result() except BadRequest as e: if e.message == 'Have no rights to send a message': pass logger.warn(e.message) time.sleep(5) try: sent.delete() except BadRequest as e: logger.warn(e.message) try: bot.kick_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 = _( '因權限不足無法踢除 {fullname}\n' '⚠️為bot正常運作,請給予admin權限⚠️').format( fullname=new_member.mention_html()) bot.send_message(text, parse_mode='html') return True return False
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 loads_(self): self.query = self.mongo.user.find_one( {'chat.id': self.update.message.from_user.id}) user = db_parse.user() user.parse(self.query) if user.config.lang: if user.config.lang.lower() in self.lang.keys(): return self.lang[user.config.lang] # .install(True) else: print(self.lang.keys()) print('not in ')
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 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 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 in_shield(user_id: 'str or int'): ''' sage + white ''' sages = [] for x in ['elf', 'michael', 'lucifer']: tmp = redis.lrange(x, 0, -1) for get_id in tmp: sages.append(int(get_id.decode())) query_user = mongo.user.find_one({'chat.id': user_id}) if query_user: user = db_parse.user() user.parse(query_user) if user.is_white: sages.append(int(user_id)) if int(user_id) in sages: return True else: return False
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 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 xmedia(bot, update): locales.i18n(update).loads.install(True) if in_shield(update.message.from_user.id): return if is_participate_white(bot, update): return query_user = mongo.user.find_one({'chat.id': update.message.from_user.id}) if query_user: user = db_parse.user() user.parse(query_user) if user.current: if datetime.fromtimestamp(user.current.until).astimezone( taiwan_country).year == 1970: return if is_admin(bot, update): return if Filters.photo(update.message): file = bytes( update.message.photo[-1].get_file().download_as_bytearray()) bio = io.BytesIO(file) i = imagehash.hashing(bio) hashing = i.phash() middle = i.indexing() query_xmedia = list( mongo.xmedia.find( {'photo.indexing': { '$gte': middle - 10, '$lte': middle + 10 }})) if query_xmedia == []: logger.info('no target found') if query_xmedia: compare_list = [] for parse in query_xmedia: media = db_parse.media() media.parse(parse) compare_list.append(media.hash) compare_result = i.plooks_like(compare_list) if compare_result[-1].judge: query_photo = mongo.xmedia.find_one( {'photo.hash': compare_result[-1].hash}) media = db_parse.media() media.parse(query_photo) if media.is_white: logger.debug(f'{hashing} in white list') return 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 check = bool( set(group.config.sub_ban_list).intersection(list(media.tags))) if not check: pass else: try: sent = update.message.forward( config.getint('log', 'evidence')).message_id except BaseException: sent = 2 else: until = druation(list(media.tags_list)) excalibur(bot, update, update.message.from_user.id, media.tags_list, media.opid, until=until, reason=media.reason, evidence=sent, user=update.message.from_user) announce_ban = _( '名字:{fullname}\n' '傳送了已被標記為 <code>{tags}</code> 的圖片,已進行處置。').format( fullname=update.message.from_user.mention_html(), tags=media.tags_text) try: update.message.delete() except BaseException: pass try: bot.restrict_chat_member(update.message.chat.id, update.message.from_user.id) except BadRequest as e: if e.message == 'User is an administrator of the chat': return elif e.message == 'Not enough rights to restrict/unrestrict chat member': text = _('⚠️權限不足⚠️\n') + announce_ban update.message.reply_html(text) return else: sent = update.message.reply_html(announce_ban).result() time.sleep(10) try: bot.delete_message(update.message.chat.id, sent.message_id) except BaseException: pass finally: homicide(bot, update, update.message.from_user.id) return # NSFW DETECT # query_group = mongo.group.find_one({'chat.id': update.message.chat.id}) if query_group is None: return group = db_parse.group() group.parse(query_group) check = bool(set(group.config.sub_ban_list_text).intersection(['p**n'])) if not check: return if group.config.ml_nsfw in [None, False]: return nsfw = nsfw_detect(file=file) if nsfw.ban: abyss = config.getint('log', 'abyss') sent = update.message.forward(abyss) evidence = update.message.forward(config.getint('log', 'evidence')) record_msg = f'Name:{update.message.from_user.mention_html()}\n' \ f'UID:<code>{update.message.from_user.id}</code>\n' \ f'Checker:<code>NSFW</code>\n' \ f'Group Name:<code>{update.message.chat.title}</code>\n' \ f'Group ID:<code>{update.message.chat.id}</code>\n' \ f'Group Username:{f"@{update.message.chat.username}" if update.message.chat.username else None}\n' \ f'NSFW Score:<code>{nsfw.score}</code>\n' \ f'#NSFW #tracker_{update.update_id}' bot.send_message(abyss, record_msg, parse_mode='html', reply_to_message_id=sent.message_id) try: text = '' bot.restrict_chat_member(update.message.chat.id, update.message.from_user.id) except BadRequest as e: if e.message == 'Not enough rights to restrict/unrestrict chat member': text = _('⚠️權限不足⚠️\n') finally: text += _('淺行系統偵測到 <code>NSFW</code> 內容媒體,依照契約將吞食內容\n' '名字:{fullname}\n' 'UID:<code>{uid}</code>\n' '若有誤判請至 @hexjudge 報告 淺行系統 存在問題。\n' '案件追蹤 ID:#tracker_{tracker_id}').format( fullname=update.message.from_user.mention_html(), uid=update.message.from_user.id, tracker_id=update.update_id) try: update.message.delete() except BaseException: pass sent = update.message.reply_html(text).result() until = int((datetime.now(taiwan_country) + timedelta(days=90)).timestamp()) time.sleep(10) bot.delete_message(update.message.chat_id, sent.message_id) excalibur(bot, update, update.message.from_user.id, ['p**n'], bot.id, until=until, reason='NSFW 自動偵測', evidence=evidence.message_id, user=update.message.from_user) homicide(bot, update, update.message.from_user.id)
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
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 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
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 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 ban_sticker(bot, update): i18n(update).loads.install(True) if update.message.forward_from: chat = update.message.forward_from elif update.message.forward_from_chat: chat = update.message.forward_from_chat else: chat = update.message.from_user if update.message.sticker.set_name is None: return if sage.in_shield(update.message.from_user.id): return group = db_parse.group() query_group = mongo.group.find_one({'chat.id': update.message.chat.id}) group.parse(query_group) if group.white_participate: if update.message.from_user.id in group.white_participate: return if is_admin(bot, update, specfic=(update.message.chat.id, update.message.from_user.id)): return ban = sticker_judge.checker(bot, update, update.message.sticker.set_name) if ban: try: evidence = update.message.forward(config.getint('log', 'evidence')) except BaseException: evidence = 2 if update.message.sticker.set_name: query_stiker = mongo.sticker.find_one( {'sticker.set_name': update.message.sticker.set_name}) if query_stiker: sticker = db_parse.sticker() sticker.parse(query_stiker) query_user = mongo.user.find_one( {'chat.id': update.message.from_user.id}) user = db_parse.user() user.parse(query_user) if sticker.day == 0: until = 0 else: until = int((datetime.now(taiwan_country) + timedelta(days=sticker.day)).timestamp()) # check group sub with sticker ban check = bool( set(group.config.sub_ban_list).intersection(sticker.tags_list)) logger.debug( f'sticker compare with group sub is {check}, should ban') if not check: return if until == 0: pass ''' 當 A 子在別的地方得到 mark as spam (ads), 在 B 群沒有訂閱 (ads) 而有訂閱 p**n, 而 A 在貼了 mark as p**n 的貼圖。 A 子會被踢出去,並且記錄在 banned_participate, 但不更新 ban.current ''' single_ban = True if user.current and user.current.until != 0: single_ban = False update.message.from_user.fullname = update.message.from_user.full_name if evidence == 2: evidence_ = sticker.evidence else: evidence_ = evidence.message_id excalibur(bot, update, update.message.from_user.id, sticker.tags, sticker.opid, until=until, reason=sticker.reason, evidence=evidence_, user=update.message.from_user) announce_ban = _( announce(update.message.from_user.id, sticker.tags, sticker.opid, until=until, reason=sticker.reason, evidence=evidence_, query_user=update.message.from_user)) else: announce_ban = _( '名字:{fullname}\n' '傳送了 <code>{sticker}</code> 已被標記為 <code>{tags}</code> 的貼圖。' ).format(fullname=user.mention_html, sticker=sticker.set_name, tags=sticker.tags_text) try: update.message.delete() except BaseException: pass try: bot.restrict_chat_member(update.message.chat.id, update.message.from_user.id) except BadRequest as e: if e.message == 'User is an administrator of the chat': return elif e.message == 'Not enough rights to restrict/unrestrict chat member': text = _('⚠️權限不足⚠️\n') + announce_ban update.message.reply_html(text) return else: sent = update.message.reply_html(announce_ban).result() time.sleep(10) try: sent.delete() except BaseException: pass homicide(bot, update, update.message.from_user.id)