Пример #1
0
def key(msg, content):
    try:
        DB[msg.chat_id] = yaml.load(content, Loader=yaml.FullLoader)
        saveDB()
        autoDestroy(msg.reply_text('success ' + getKeysText(msg), quote=False))
    except Exception as e:
        msg.reply_text(str(e), quote=False)
Пример #2
0
def handleCommand(update, context):
	msg = update.effective_message
	if not msg:
		return
	handleAdmin(msg)
	if not msg.text.startswith('/wb'):
		return
	command, text = splitCommand(msg.text)
	if 'unsub' in command:
		result = subscription.remove(msg.chat_id, text)
		try:
			scheduled_key.remove(result)
		except:
			...
	elif 'sub' in command:
		result = subscription.add(msg.chat_id, text)
		scheduled_key.append(result)
	reply = msg.reply_text(subscription.get(msg.chat_id), 
		parse_mode='markdown', disable_web_page_preview=True)
	if msg.chat_id < 0:
		tryDelete(msg)
	if 'sub' in command:
		commitRepo(delay_minute=0)
		if msg.chat_id < 0:
			autoDestroy(reply, 0.1)
Пример #3
0
def export(update, context):
    if update.edited_message or update.edited_channel_post:
        return
    msg = update.effective_message
    if msg.chat_id < 0 and 'source</a>' in msg.text_html_urled:
        return
    if msg.chat.username == 'web_record':
        if (matchKey(msg.text_markdown,
                     ['twitter', 'weibo', 'douban', 't.me/'])
                and not matchKey(msg.text_markdown, ['article', 'note'])):
            return
    try:
        tmp_msg_1 = msg.chat.send_message('received')
    except:
        return
    error = ''
    result = []
    try:
        result = list(exportImp(msg))
        if str(msg.chat.id) in remove_origin._db.items:
            tryDelete(msg)
    except Exception as e:
        tmp_msg_2 = msg.chat.send_message(str(e))
        autoDestroy(tmp_msg_2, 0.05)
        error = ' error: ' + str(e)
    finally:
        info_log.send_message(getBasicLog(msg) + error + ' result: ' +
                              ' '.join(result),
                              parse_mode='html',
                              disable_web_page_preview=True)
        tmp_msg_1.delete()
def command(update, context):
	msg = update.effective_message
	try:
		commandImp(msg)
	except Exception as e:
		autoDestroy(msg.reply_text(str(e)))
		tb.print_exc()
		raise e
Пример #5
0
def command(update, context):
	msg = update.channel_post
	if msg.chat_id != douban_channel.id:
		return
	r = commandInternal(msg)
	if not r:
		return
	autoDestroy(msg.reply_text(r), 0.1)
	msg.delete()
def handleCommand(update, context, dbs):
    msg = update.effective_message
    autoDestroy(msg, 0.1)
    if msg.from_user and matchKey(msg.from_user.first_name, ['telegram']):
        # don't deal with group message auto forwarded linked channel
        return
    command, text = splitCommand(msg.text)
    if 's3_l' in command:
        subscriptions = dbs.getList(msg.chat_id)
        subscriptions = [str(index) + ': ' + \
            formatChat(context.bot, x['id']) for \
            index, x in enumerate(subscriptions)]
        r = msg.reply_text('subscription list: \n\n' +
                           '\n'.join(subscriptions),
                           quote=False,
                           parse_mode='Markdown',
                           disable_web_page_preview=True)
        autoDestroy(r)
        return
    if 's3_un' in command:
        try:
            index = int(text)
        except:
            r = msg.reply_text('please give index')
            autoDestroy(r)
            return
        r = dbs.deleteIndex(msg.chat_id, index)
        autoDestroy(msg.reply_text(r, quote=False))
        return
    if 's3_s' in command:
        chat = getChat(context.bot, text)
        if not chat:
            return
        r = dbs.add(msg.chat, chat)
        autoDestroy(msg.reply_text(r, quote=False))
        return
    if not msg.from_user or msg.from_user.id != debug_group.id:
        return
    if 'repeat' in command:
        msg.bot.send_message(msg.chat.id,
                             msg.reply_to_message.text_markdown,
                             parse_mode='Markdown',
                             disable_web_page_preview=True)
    # guard this feature
    # if 'all' in command:
    #     sendAll(msg, dbs)
    #     return
    if 'delete' in command:
        to_delete = msg.reply_to_message
        key = (to_delete.chat_id, to_delete.message_id)
        for r in forward_all_record[key]:
            try:
                r.delete()
            except:
                pass
Пример #7
0
def handleAdmin(msg, command, text):
	if not text:
		return
	success = False
	if command == '/abl':
		blocklist.add(text)
		success = True
	if success:
		autoDestroy(msg.reply_text('success'), 0.1)
		tryDelete(msg)
		commitRepo(delay_minute=0)
Пример #8
0
def manage(update, context):
    chat_id = update.effective_chat and update.effective_chat.id
    if not chat_id:
        return
    msg = update.effective_message
    if not msg:
        return
    command, text = splitCommand(msg.text)
    if 'interval' in command:
        db.setInterval(chat_id, int(text))
        autoDestroy(msg.reply_text('success'), 0.1)
        msg.delete()
    db.setTime(chat_id)
Пример #9
0
def deleteTargetMsg(msg):
	for target_chat_id, target_msg_id, url in getTargetMsgs(msg):
		reply_msg = None
		try:
			if msg.text in ['md', 'kd', 'k', 'm']:
				reply_msg = bot.send_message(target_chat_id, '非常抱歉,您的信息被机器人认为有广告的嫌疑,已转交人工审核。审核通过后会归还您发言的权利。', reply_to_message_id = target_msg_id)
			if msg.text in ['d', 'mmd', 'od']:	
				reply_msg = bot.send_message(target_chat_id, '非常抱歉,本群不支持转发与多媒体信息,我们将在1分钟后自动删除您的消息。', reply_to_message_id = target_msg_id)
			if msg.text not in ['k', 'm']:
				bot.delete_message(target_chat_id, target_msg_id)
				msg.edit_text('deleted: ' + url)
		except:
			msg.edit_text('reply original message failed: ' + url)
		if reply_msg:
			autoDestroy(reply_msg, 0.2)
Пример #10
0
def handleAdmin(msg):
    if msg.chat.username not in ['b4cxb', 'weibo_read', 'weibo_one']:
        return
    command, text = splitCommand(msg.text)
    if not text:
        return
    success = False
    if command == '/abl':
        blocklist.add(text)
        success = True
    if command == '/apl':
        popularlist.add(text)
        success = True
    if success:
        autoDestroy(msg.reply_text('success'), 0.1)
        tryDelete(msg)
        commitRepo(delay_minute=0)
Пример #11
0
def handleCommand(update, context):
	msg = update.effective_message
	command, text = splitCommand(msg.text)
	if msg.chat.username in ['twitter_read']:
		handleAdmin(msg, command, text)
	if not msg or not msg.text.startswith('/tw'):
		return
	success = False
	if 'unsub' in command:
		subscription.remove(msg.chat_id, text)
		success = True
	elif 'sub' in command:
		subscription.add(msg.chat_id, text)
		success = True
	r = msg.reply_text(subscription.getSubscription(msg.chat_id), 
		parse_mode='markdown', disable_web_page_preview=True)
	if msg.chat_id < 0:
		tryDelete(msg)
		if success:
			autoDestroy(r, 0.1)
Пример #12
0
def handleCommand(update, context):
	msg = update.effective_message
	if not msg or not (msg.text.startswith('/web') or msg.text.startswith('/abl ')):
		return
	command, text = splitCommand(msg.text)
	if 'remove' in command:
		text = text.strip('/')
		db.sub.remove(msg.chat_id, text)
		try:
			scheduled.remove(text)
		except:
			...
	elif 'add' in command:
		config = text.split()
		site = config[0].strip('/')
		config = normalizeConfig(config[1:])
		db.sub.add(msg.chat_id, site, config)
		scheduled.append(site)
	elif 'backfill' in command:
		tryDelete(msg)
		backfill(msg.chat_id)
	elif command == '/abl':
		text = text.strip()
		if tooShort(text):
			reply = msg.reply_text('too short')
		elif text in blocklist.get(msg.chat_id, []):
			reply = msg.reply_text('block item already exist')
		else:
			blocklist[msg.chat_id] = blocklist.get(msg.chat_id, []) + [text]
			with open('blocklist', 'w') as f:
				f.write(yaml.dump(blocklist, sort_keys=True, indent=2, allow_unicode=True))
			reply = msg.reply_text('success')
		autoDestroy(reply, 0.05)
		tryDelete(msg)
	if msg.text.startswith('/web'):
		reply = msg.chat.send_message(db.sub.get(msg.chat_id), disable_web_page_preview=True)
		tryDelete(msg)
		if matchKey(msg.text, ['add', 'remove']):
			autoDestroy(reply, 0.05)
Пример #13
0
def manage(update, context):
    msg = update.effective_message
    if not msg:
        return
    autoDestroy(msg)
    command, content = splitCommand(msg.text)
    if ('add' in command) and content:
        return add(msg, content)
    if 'list' in command:
        return listPool(msg)
    if 'remove' in command:
        return remove(msg, content)
    if 'show' in command:
        return show(msg)
    if 'key' in command:
        return key(msg, content)
    if 'pause' in command:
        global PAUSED
        PAUSED.append(msg.chat_id)
        threading.Timer(4 * 60 * 60, lambda: unpause(msg.chat_id)).start()
        autoDestroy(msg.reply_text('success', quote=False))
        return
def commandImp(msg):
	autoDestroy(msg)
	command, text = splitCommand(msg.text)
	if "s4_g" in command:
		return msg.reply_text(iterateMessage(msg.chat.id), quote=False)
	elif matchKey(command, ["s4_source_add", "s4_sa", "s4_a"]):
		autoDestroy(msg.reply_text(Source.add(text)))
	elif matchKey(command, ["s4_source_delete", "s4_sd", "s4_d"]):
		autoDestroy(msg.reply_text(Source.remove(text)))
	elif matchKey(command, ["s4_source_list", "s4_sl", "s4_l"]):
		pass # intentional
	elif matchKey(command, ["s4_sub", "s4_s"]):
		Subscription.add(msg.chat.id, text)
	else:
		return
	if matchKey(command, ["s4_source", "s4_sl", "s4_l", "s4_sa", "s4_a", "s4_sd", "s3_d"]):
		sources = ['[%s](t.me/%s)' % (chatname, chatname) for \
			chatname in Source.db.keys()]
		autoDestroy(msg.reply_text('Source list: \n' + '\n'.join(sources), 
			parse_mode='Markdown', 
			disable_web_page_preview=True))
	else:
		autoDestroy(msg.reply_text("success"))
def remindIfNecessary(msg):
    if not msg.text:
        return
    if matchKey(msg.text,
                better_avoid_words) and not matchKey(msg.text, quotes):
        reminder = '建议避免使用带有强烈主观判断的词哦,比如:' + ', '.join(better_avoid_words) + \
         '。 谢谢啦!'
        autoDestroy(msg.reply_text(reminder), 10)
    emotional_words = ['意淫', '凭什么']
    if matchKey(
            msg.text,
            emotional_words) or msg.text.count('?') + msg.text.count('?') >= 3:
        reminder = '反问,反讽不利于友好交流哦,建议您换成大家更容易理解的表达哦。谢谢啦!'
        autoDestroy(msg.reply_text(reminder), 10)
    attacking_words = ['太low']
    if matchKey(msg.text, attacking_words):
        reminder = '请友好交流,争取互相理解。谢谢啦!'
        autoDestroy(msg.reply_text(reminder), 10)
Пример #16
0
	for item in msg.entities:
		if (item["type"] == "url"):
			url = msg.text[item["offset"]:][:item["length"]]
			if not '://' in url:
				url = "https://" + url
			u = getTelegraph(msg, url)
			msg.reply_text(u)
			if msg.from_user.id not in known_users:
				r = debug_group.send_message( 
					text=getDisplayUser(msg.from_user) + ': ' + u, 
					parse_mode='Markdown')

@log_on_fail(debug_group)
def command(update, context):
	msg = update.effective_message
    autoDestroy(msg)
    command, text = splitCommand(msg.text)
    if command == "cn_article_get":
    	pass # TODO
    elif command == "cn_article_subscribe":
    	pass # TODO
    elif command == "an_article_source_add":
    	sub_db.add(text)
    elif command == "an_article_source_delete":
    	sub_db.remove(text)
    else:
    	return
    autoDestroy(msg.reply_text("success"))

tele.dispatcher.add_handler(MessageHandler(Filters.update.channel_posts & Filters.command, command))
Пример #17
0
def show(msg):
    autoDestroy(msg.reply_text(getKeysText(msg), quote=False))