fix: downgrading python-telegram-bot version
This commit is contained in:
parent
f236aa0aed
commit
a652dac9bd
@ -1,18 +1,24 @@
|
|||||||
|
'''
|
||||||
|
python-telegram-bot: 13.7, version 20.XX cannot work
|
||||||
|
'''
|
||||||
|
|
||||||
from urllib import response
|
from urllib import response
|
||||||
from cairo import Filter
|
from cairo import Filter
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
import torch
|
import torch
|
||||||
from telegram.ext import MessageHandler, CallbackContext, CommandHandler, filters, Application
|
from telegram.ext import MessageHandler, CallbackContext, CommandHandler, Filters, Updater
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
TOKEN = ""
|
TOKEN = "6207011315:AAH-J0zjPPd_mDPN1_pCgll0w-pZtlJXYVY"
|
||||||
|
|
||||||
class BankBot():
|
class BankBot():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.application = Application.builder().token(TOKEN).build()
|
self.updater = Updater(TOKEN, use_context=True)
|
||||||
self.application.add_handler(CommandHandler('shop', self.addShop))
|
self.dispatcher = self.updater.dispatcher
|
||||||
self.application.add_handler(MessageHandler(filters.ALL, self.response))
|
self.dispatcher.add_handler(CommandHandler('start', self.start))
|
||||||
|
self.dispatcher.add_handler(CommandHandler('add', self.add))
|
||||||
|
self.dispatcher.add_handler(MessageHandler(Filters.text, self.echo))
|
||||||
|
|
||||||
if os.path.isfile('./client.json'):
|
if os.path.isfile('./client.json'):
|
||||||
with open("client.json") as fp:
|
with open("client.json") as fp:
|
||||||
@ -21,28 +27,23 @@ class BankBot():
|
|||||||
self.clients = {}
|
self.clients = {}
|
||||||
|
|
||||||
def start_polling(self):
|
def start_polling(self):
|
||||||
print("start...")
|
self.updater.start_polling()
|
||||||
self.application.run_polling()
|
|
||||||
|
|
||||||
async def response(self, update, context):
|
|
||||||
q = update.message.text
|
|
||||||
|
|
||||||
await context.bot.send_message(
|
|
||||||
chat_id=update.effective_chat.id,
|
|
||||||
text="我看不懂這個 {} 指令".format(q)
|
|
||||||
)
|
|
||||||
|
|
||||||
async def addShop(self, update, context):
|
def echo(self, update, context):
|
||||||
|
message = update.message.text
|
||||||
|
context.bot.send_message(chat_id=update.effective_chat.id, text="我看不懂 {} 指令".format(message))
|
||||||
|
|
||||||
|
def add(self, update, context):
|
||||||
args = context.args
|
args = context.args
|
||||||
|
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
await context.bot.send_message(
|
context.bot.send_message(chat_id=update.effective_chat.id, text="usage: /start YOUR_ADDRESS")
|
||||||
chat_id=update.effective_chat.id,
|
|
||||||
text="usage: /shop [YOUR_ADDRESS]"
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
address = args[0]
|
address = args[0]
|
||||||
this.client[address] = update.effective_chat.id
|
self.clients[address] = update.effective_chat.id
|
||||||
await context.bot.send_message(
|
with open('client.json', 'w') as fp:
|
||||||
chat_id=update.effective_chat.id,
|
json.dump(self.clients, fp)
|
||||||
text="已經設定 {} 的店家收款通知!"
|
context.bot.send_message(chat_id=update.effective_chat.id, text="開始追蹤 {} 的商店收款通知".format(address))
|
||||||
)
|
|
||||||
|
def start(self, update, context):
|
||||||
|
context.bot.send_message(chat_id=update.effective_chat.id, text="Hi, 這是暨大區塊鏈銀行 Telegram Bot\n\n/add YOUR_ADDRESS: 追蹤出入帳通知")
|
||||||
@ -3,6 +3,8 @@ import sqlite3
|
|||||||
import os
|
import os
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
from bot import BankBot
|
from bot import BankBot
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
CORS(app)
|
CORS(app)
|
||||||
@ -169,14 +171,14 @@ def add_products(address):
|
|||||||
|
|
||||||
return jsonify({'status': 'OK'})
|
return jsonify({'status': 'OK'})
|
||||||
|
|
||||||
|
def start_flask():
|
||||||
|
app.run(host="0.0.0.0")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
initDB()
|
initDB()
|
||||||
|
|
||||||
app.run(host="0.0.0.0")
|
|
||||||
|
|
||||||
print("start the bot...")
|
|
||||||
bot = BankBot()
|
bot = BankBot()
|
||||||
|
print("start polling...")
|
||||||
bot.start_polling()
|
bot.start_polling()
|
||||||
bot.application.idle()
|
|
||||||
|
flask_thread = threading.Thread(target=start_flask)
|
||||||
|
flask_thread.start()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user