Skip to content

Commit

Permalink
add telebot
Browse files Browse the repository at this point in the history
  • Loading branch information
nanjingblue committed Jun 13, 2021
1 parent 363cbf0 commit 331a65a
Show file tree
Hide file tree
Showing 16 changed files with 217 additions and 2 deletions.
6 changes: 6 additions & 0 deletions bilibiliflask/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified bilibiliflask/__pycache__/app.cpython-38.pyc
Binary file not shown.
Binary file modified bilibiliflask/__pycache__/setuitem.cpython-38.pyc
Binary file not shown.
10 changes: 8 additions & 2 deletions bilibiliflask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@
def index():
return 'Hello world'

@app.route('/getsetu', methods=['GET'])
def get_setu():
setu = SetuItem()
link = setu.get_setu()
return jsonify(link)

@app.route('/setus', methods=['GET'])
def get_setus():
setu = SetuItem()
data = setu.get_setus()
print(data)
print("获取成功!")
return jsonify(data)
setu.close()
return jsonify(data)

@app.route('/setu', methods=['GET'])
def get_setu():
def get_setu_img():
setu = SetuItem()
link = str(setu.get_setu())
return render_template('index.html', link=link)
Expand Down
8 changes: 8 additions & 0 deletions setubot/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions setubot/.idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions setubot/.idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions setubot/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions setubot/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions setubot/.idea/mytelebot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions setubot/BotConfig.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

TOKEN = '1829725347:AAGEUC1uVH5PLfbN5s1Wu645SG2Qtwdzr8A'
chat_id = '917866835'
45 changes: 45 additions & 0 deletions setubot/BotInit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import random
import time
import telebot
import BotConfig, GetSetu


random.seed(time.time())

TOKEN = '1829725347:AAGEUC1uVH5PLfbN5s1Wu645SG2Qtwdzr8A'

bot = telebot.TeleBot(BotConfig.TOKEN, parse_mode=None)

# bot.send_message(BotConfig.chat_id, '你寄吧谁')

# 定义 /start 和 /help 命令
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, 'Howdy, how are you doing?')

# 将所有传入的文本消息回显给发件人。它使用 lambda 函数来测试消息。如果 lambda 返回 True,则消息由装饰函数处理。
# 因为我们希望所有消息都由这个函数处理,所以我们总是简单地返回 True。
# @bot.message_handler(func=lambda m: True)
# def echo_all(message):
# bot.reply_to(message, message.text)

# 儒雅随和
# @bot.message_handler(content_types=['text'])
# def send_jb(message):
# list1 = ['傻逼', '你寄吧谁啊', '我是你爹', '操你妈', '去死', '什么玩意儿', '恶心心', '你真tm丑']
# list2 = ['鸡掰', '粑粑粑粑', '操', '甘霖娘', '甘霖娘鸡掰', '操他妈你不要再讲了好不好', '小屁孩','好了 你不要再讲了']
# reply = random.choice(list2)
# bot.reply_to(message, reply)

@bot.message_handler(content_types=['text'])
def send_SeTu(message):
if message.text == '色图':
bot.send_message(message.chat.id, '想屁吃')
img = GetSetu.getSetu()
bot.send_photo(message.chat.id, img)

bot.polling()
bot.polling(none_stop=True)
bot.polling(interval=3)
while True:
pass
27 changes: 27 additions & 0 deletions setubot/EchoBot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import telebot
import time
import BotConfig

TOKEN = '1829725347:AAGEUC1uVH5PLfbN5s1Wu645SG2Qtwdzr8A'

def listener(messages):
"""
When new messages arrive TeleBot will call this function.
"""
for m in messages:
chatid = m.chat.id
if m.content_type == 'text':
text = m.text
tb.send_message(chatid, text)


tb = telebot.TeleBot(TOKEN)
tb.set_update_listener(listener) #register listener
tb.polling()
#Use none_stop flag let polling will not stop when get new message occur error.
tb.polling(none_stop=True)
# Interval setup. Sleep 3 secs between request new message.
tb.polling(interval=3)

while True: # Don't let the main Thread end.
pass
6 changes: 6 additions & 0 deletions setubot/GetSetu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import requests

url = 'http://127.0.0.1:5000/getsetu'
def getSetu():
req = requests.get(url)
return req.json()
Binary file added setubot/__pycache__/BotConfig.cpython-38.pyc
Binary file not shown.
Binary file added setubot/__pycache__/GetSetu.cpython-38.pyc
Binary file not shown.

0 comments on commit 331a65a

Please sign in to comment.