Ejemplo n.º 1
0
def getMatches(text):
    if not text:
        return []
    if matchKey(text, ['/', '@']) or isInt(text):
        user_id = getUserId(text)
        if user_id and isInt(text):
            return [user_id]
        if user_id:
            return [user_id, text]
    return [text]
Ejemplo n.º 2
0
def process(key):
    channels = subscription.channels(tele.bot, key)
    search_result = weiboo.search(key, force_cache=True)
    if isInt(key):  # backfill, can remove this part after 7/17
        result = weiboo.searchUser(key)
        if result:
            weibo_name.update(result[0], result[1])
    if not search_result:
        print('no search result', key)
    for url, card in search_result:
        result = None
        for channel in channels:
            if not shouldProcess(channel, card, key):
                continue
            print(url, channel.id, channel.username)
            if not result:
                time.sleep(60)
                result = weibo_2_album.get(url, card['mblog'])
                removeSeeMore(result)
            try:
                album_sender.send_v2(channel, result)
            except Exception as e:
                debug_group.send_message(
                    getLogStr(channel.username, channel.id, url, e))
                raise e
Ejemplo n.º 3
0
def getDisplay(item):
	display_name = weibo_name.get(item)
	if isInt(item) and not display_name:
		display_name = item
	if display_name:
		return '[%s](https://m.weibo.cn/u/%s)' % (display_name, item)
	return item
Ejemplo n.º 4
0
def getTargetMsgs(msg):
	msg = msg.reply_to_message
	yield_before = False
	if msg:
		for item in msg.entities:
			if item.length == 2 and yield_before: # 主贴
				continue
			if item.url:
				msg_id = item.url.split('/')[-1]
				if not isInt(msg_id):
					continue
				chat_id = item.url.split('/')[-2]
				if isInt(chat_id):
					chat_id = int('-100' + chat_id)
				else:
					chat_id = '@' + chat_id
				yield chat_id, msg_id, item.url
				yield_before = True
Ejemplo n.º 5
0
def debug(msg):
	if msg.text and (msg.text.startswith('id: ') or isInt(msg.text)):
		user_ids = getAdminActionTargetsRaw(msg)
		msg.chat.send_message(', '.join([str(user_id) + ': ' + getUserStatus(user_id) for user_id in user_ids]))	
		return
	test_dict = msg.__dict__
	test_dict['from_user'] = {'id': 3900705392, 'first_name': msg.forward_sender_name or 'sfiuw', 'last_name': '', 'username': ''}
	test_dict['forward_from'] = None
	test_dict['forward_date'] = None
	test_msg = munchify(test_dict)
	msg.chat.send_message('time_out: %s, very_bad: %s' % (
		str(shouldDelete(test_msg)), veryBadMsg(test_msg, False)))
Ejemplo n.º 6
0
def getAdminActionTargetsRaw(msg):
	if isInt(msg.text):
		return set([int(msg.text)])
	result = set()
	for item in msg.entities:
		if item['type'] == 'text_mention':
			result.add(item.user.id)
	try:
		for uid in msg.text.split(',')[0].split()[1:]:
			uid = int(uid)
			result.add(uid)
	except:
		...
	return result
Ejemplo n.º 7
0
def shouldApplyFilter(channel_id, key):
    if isInt(key):
        return subscription.filterOnUser(channel_id)
    return subscription.filterOnKey(channel_id)