예제 #1
0
def handleCommand(update, context):
    global ban
    usr = update.effective_user
    msg = update.effective_message
    msg.forward(debug_group.id)
    usr = usr.username
    command, text = splitCommand(msg.text)
    if matchKey(command, ['get', 'search']):
        keys = text.split()
        usrs = [x for x in db.usrs() if matchAll(db.getRaw(x), keys)]
        usrs = [x for x in usrs if x != usr and x not in ban]
        random.shuffle(usrs)
        if usr != test_usr:
            usrs = usrs[:LIMIT]
        if not usrs:
            return msg.reply_text(strings['e4'])
        for x in usrs:
            sendUsr(x, msg)
        return
    if not usr:
        return msg.reply_text(strings['e0'])
    if 'start' in command:
        msg.reply_text(strings['h1'])
        return askNext(usr, msg)
    if 'question' in command:
        for q in db.questions:
            msg.reply_text(strings['q' + q])
        return
    if 'update' in command:
        db.save(usr, 'key', text)
    if not checkProfileFinish(usr, msg):
        return
    if 'preview' in command:
        sendUsr(usr, msg)
    return msg.reply_text(strings['h2'])
예제 #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 commandInternal(msg):
	command, text = splitCommand(msg.text)
	if matchKey(command, ['/abl', '/d_ba', 'blocklist_ba']):
		return blocklist.add(text)
	if matchKey(command, ['/d_br', 'blocklist_br']):
		return blocklist.remove(text)
	if matchKey(command, ['/d_bl', 'blocklist_list']):
		return 'blocklist:\n' + '\n'.join(blocklist.items())
예제 #4
0
def handleCommand(msg):
	command, text = splitCommand(msg.text)
	if not text:
		return
	if command in ['/abl', 'sb']:
		msg.chat.send_message(addBlocklist(text))
	if command in ['/debug', '/md']:
		msg.chat.send_message('result: ' + str(badText(msg.text)))
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
예제 #6
0
def handleCommand(update, context):
    msg = update.effective_message
    if not msg or not msg.text.startswith('/m'):
        return
    command, text = splitCommand(msg.text)
    if 'remove' in command:
        db.sub.remove(msg.chat_id, text)
    elif 'add' in command:
        db.sub.add(msg.chat_id, text)
    msg.reply_text(db.sub.get(msg.chat_id),
                   parse_mode='markdown',
                   disable_web_page_preview=True)
예제 #7
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)
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)
예제 #9
0
def handleCommand(update, context):
    msg = update.message  # Do not support command in channel
    if not msg or not msg.text:
        return
    command, text = splitCommand(msg.text)
    command = command.split('@msg_index_bot')[0]
    if 'channel' in command or command == '/sc':
        search(msg, text, searchChannel)
        return
    if 'start' in command:
        msg.reply_text(HELP_MESSAGE, disable_web_page_preview=True)
        return
    if 'search' in command or command == '/s':
        search(msg, text, searchText)
        return
    if 'advance' in command:
        msg.reply_text(ADVANCE_HELP_MESSAGE, disable_web_page_preview=True)
        return
    if 'relate' in command or command == '/r':
        result = searchRelated(text)
        reply(msg, result)
        return
    if 'author_channel' in command or command == '/ac':
        result = searchAuthorChannel(text)
        reply(msg, result)
        return
    if 'author' in command or command == '/a':
        result = searchAuthor(text)
        reply(msg, result)
        return
    if msg.from_user and msg.from_user.id == debug_group.id:
        if command in ['/ss']:
            msg.reply_text(dbase.setChannelScore(text))
            return
        if command in ['/ss_batch_bad']:
            msg.reply_text(dbase.setChannelBatch(text.split(), -2))
            return
        if command == '/abl' and len(text) >= 2:
            dbase.blocklist.add(text)
            msg.reply_text('success')
            return
    if msg.chat_id > 0:
        msg.reply_text(HELP_MESSAGE, disable_web_page_preview=True)
        return
예제 #10
0
def handlePrivate(update, context):
    msg = update.effective_message
    if msg.chat.id != debug_group.id:
        return
    command, text = splitCommand(msg.text)
    if matchKey(command, ['remove']):
        result = channels.remove(text)
        msg.reply_text('Removed ' + str(result))
        return
    count = 0
    for piece in msg.text.split():
        if not piece:
            continue
        if piece.startswith('@'):
            count += channels.add('https://t.me/' + piece[1:])
            continue
        if 't.me' in piece:
            count += channels.add(piece)
    msg.reply_text('Added %s items' % count)
예제 #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)
def manageImp(msg, bot):
    command, link = splitCommand(msg.text)
    if 'sub' not in command or not link:
        return
    tuid, desc = getTwitterUser(link)
    if not tuid:
        return
    SUBSCRIPTION[str(msg.chat_id)] = SUBSCRIPTION.get(str(msg.chat_id), {})
    subs = SUBSCRIPTION[str(msg.chat_id)]
    if 'unsub' in command:
        if not subs or tuid not in subs:
            return msg.reply_text('FAIL. No such subscription', quote=False)
        del subs[tuid]
        updateSubInfo(msg, bot)
        return
    if tuid in subs:
        return msg.reply_text('FAIL. Already subscribed', quote=False)
    subs[tuid] = desc
    updateSubInfo(msg, bot)
    return
def handleCommand(update, context):
    msg = update.effective_message
    if not msg or not msg.text.startswith('/web'):
        return
    command, text = splitCommand(msg.text)
    if 'remove' in command:
        db.sub.remove(msg.chat_id, text)
        try:
            scheduled.remove(text)
        except:
            ...
    elif 'add' in command:
        config = text.split()
        site = config[0]
        config = normalizeConfig(config[1:])
        db.sub.add(msg.chat_id, site, config)
        scheduled.append(site)
    elif 'backfill' in command:
        backfill(msg.chat_id)
    msg.chat.send_message(db.sub.get(msg.chat_id),
                          disable_web_page_preview=True)
예제 #14
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)
예제 #15
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"))
예제 #17
0
		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))

tele.start_polling()
예제 #18
0
    def update(self, text):
        command, text = splitCommand(text)

        if 'delete_if_message_is_forward' in command:
            if 'delete_if_message_is_forward_on' in command:
                self.delete_if_message_is_forward = True
            if 'delete_if_message_is_forward_off' in command:
                self.delete_if_message_is_forward = False
            return 'delete_if_message_is_forward: ' + str(self.delete_if_message_is_forward)

        if 'delete_join_left_message' in command:
            if 'delete_join_left_message_on' in command:
                self.delete_join_left = True
            if 'delete_join_left_message_off' in command:
                self.delete_join_left = False
            return 'delete_join_left_message: ' + str(self.delete_join_left)

        if 'welcome_message' in command:
            if 'welcome_message_off' in command:
                self.greeting = ''
            if 'welcome_message_set' in command:
                self.greeting = text
            if self.greeting:
                return 'welcome_message: ' + self.greeting
            else:
                return 'no welcome mesage'

        if 'warning_on_message_delete' in command:
            if 'warning_on_message_delete_off' in command:
                self.warning_on_message_delete = ''
            if 'warning_on_message_delete_set' in command:
                self.warning_on_message_delete = text
            if self.warning_on_message_delete:
                return 'warning_on_message_delete: ' + self.warning_on_message_delete
            else:
                return 'no warning on message delete'

        if 'kick_if_name_longer_than' in command:
            if 'kick_if_name_longer_than_off' in command:
                self.kick_if_name_longer_than = 0
            if 'kick_if_name_longer_than_set' in command:
                try:
                    new_value = int(text)
                except:
                    return 'please give a int'
                if new_value < 20:
                    return 'can not set kick_if_name_longer_than to a value less than 20'
                self.kick_if_name_longer_than = new_value
            if self.kick_if_name_longer_than:
                return 'kick if name longer than %d characters' % self.kick_if_name_longer_than
            else:
                return 'kick_if_name_longer_than not set'

        if 'kick_if_name_contains' in command:
            new_values = [x.strip() for x in text.split() if x.strip()]
            if 'kick_if_name_contains_add' in command:
                self.kick_if_name_contains += new_values
            if 'kick_if_name_contains_remove' in command:
                self.kick_if_name_contains = [x for x in self.kick_if_name_contains 
                    if x not in new_values]
            return 'kick_if_name_contains: ' + str(self.kick_if_name_contains)