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 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 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 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 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 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 quickban(bot, update): query = update.callback_query i18n(update).loads.install(True) callback = callabck_parse.callback_parse(query.data) user_id, msg_id = callback.qact.split(':') tags = callback.qdata if sage.michael(query.from_user.id) == False and sage.lucifer( query.from_user.id) == False: query.answer('權限不夠。') return if sage.in_shield(int(user_id)): text = query.message.text_html + '\n被保護ㄉ狀態。' query.edit_message_text(text, parse_mode='html') return try: sent = update.message.forward(config.getint('log', 'evidence')) except BaseException: sent = 2 days = druation([tags]) if days != 0: until = int( (datetime.now(taiwan_country) + timedelta(days=days)).timestamp()) else: until = 0 excalibur(bot, update, int(user_id), [tags], query.from_user.id, until=until, reason=tags) text = query.message.text_html + \ f'\n{"="*23}' + \ _(f'\n處刑人:{query.from_user.mention_html()}\n') + \ _(f'標籤:<code>{tags}</code>') query.edit_message_text(text, parse_mode='html')
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 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)