-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
45 lines (37 loc) · 1.56 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import telebot
from telebot import types
import purify
from dotenv import load_dotenv
BOT_TOKEN = os.getenv('BOT_TOKEN')
print("BOT_TOKEN: ", BOT_TOKEN)
bot = telebot.TeleBot(BOT_TOKEN)
@bot.message_handler(commands=['start', 'hello'])
def send_welcome(message):
bot.reply_to(message, "你好, 这里是链接净化Bot, 可以帮你把链接的跟踪参数清除, 甚至是诸如 B23.tv/XXXXX 的短链接")
@bot.message_handler(func=lambda msg: True)
def reply_purify_link(message):
text = message.text
clean_url = purify.process_url(text)
bot.reply_to(message, clean_url)
@bot.inline_handler(lambda query: True)
def query_text(inline_query):
text = inline_query.query
try:
clean_url = purify.process_url(text)
replaced_text = purify.replace_url(text, clean_url)
r = types.InlineQueryResultArticle('1', '发送净化后的链接', types.InputTextMessageContent(clean_url))
r2 = types.InlineQueryResultArticle('2', '替换原文链接为净化链接发送', types.InputTextMessageContent(replaced_text))
bot.answer_inline_query(inline_query.id, [r, r2])
except Exception as e:
print(e)
'''
@bot.inline_handler(lambda query: query.query == 'text')
def query_text(inline_query):
try:
r = types.InlineQueryResultArticle('1', 'Result1', types.InputTextMessageContent('hi'))
r2 = types.InlineQueryResultArticle('2', 'Result2', types.InputTextMessageContent('hi'))
bot.answer_inline_query(inline_query.id, [r, r2])
except Exception as e:
print(e)'''
bot.infinity_polling()