diff --git a/bot/main.py b/backend/bot.py similarity index 69% rename from bot/main.py rename to backend/bot.py index 61aa725..4a4c462 100644 --- a/bot/main.py +++ b/backend/bot.py @@ -2,15 +2,23 @@ from urllib import response from cairo import Filter from telegram import Update import torch -from telegram.ext import Application, MessageHandler, CallbackContext, CommandHandler, filters +from telegram.ext import MessageHandler, CallbackContext, CommandHandler, filters, Application +import json +import os TOKEN = "" class BankBot(): def __init__(self): self.application = Application.builder().token(TOKEN).build() - self.application.add_handler(MessageHandler(filters.ALL, self.response)) self.application.add_handler(CommandHandler('shop', self.addShop)) + self.application.add_handler(MessageHandler(filters.ALL, self.response)) + + if os.path.isfile('./client.json'): + with open("client.json") as fp: + self.clients = json.load(fp) + else: + self.clients = {} def start_polling(self): print("start...") @@ -21,7 +29,7 @@ class BankBot(): await context.bot.send_message( chat_id=update.effective_chat.id, - text=q + text="我看不懂這個 {} 指令".format(q) ) async def addShop(self, update, context): @@ -33,12 +41,8 @@ class BankBot(): ) else: address = args[0] + this.client[address] = update.effective_chat.id await context.bot.send_message( chat_id=update.effective_chat.id, - text=address + text="已經設定 {} 的店家收款通知!" ) - -if __name__ == '__main__': - - bot = BankBot() - bot.start_polling() \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 7a412ad..f4272f6 100644 --- a/backend/main.py +++ b/backend/main.py @@ -2,6 +2,7 @@ from flask import Flask, request, jsonify import sqlite3 import os from flask_cors import CORS +from bot import BankBot app = Flask(__name__) CORS(app) @@ -165,9 +166,17 @@ def add_products(address): (shop_id, product['name'], product['code'], product['price'])) db.commit() db.close() + return jsonify({'status': 'OK'}) + if __name__ == '__main__': initDB() + app.run(host="0.0.0.0") + + print("start the bot...") + bot = BankBot() + bot.start_polling() + bot.application.idle() \ No newline at end of file