Compare commits

..

2 Commits

3 changed files with 24 additions and 10 deletions

View File

@ -2,15 +2,23 @@ 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 Application, MessageHandler, CallbackContext, CommandHandler, filters from telegram.ext import MessageHandler, CallbackContext, CommandHandler, filters, Application
import json
import os
TOKEN = "" TOKEN = ""
class BankBot(): class BankBot():
def __init__(self): def __init__(self):
self.application = Application.builder().token(TOKEN).build() 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(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): def start_polling(self):
print("start...") print("start...")
@ -21,7 +29,7 @@ class BankBot():
await context.bot.send_message( await context.bot.send_message(
chat_id=update.effective_chat.id, chat_id=update.effective_chat.id,
text=q text="我看不懂這個 {} 指令".format(q)
) )
async def addShop(self, update, context): async def addShop(self, update, context):
@ -33,12 +41,8 @@ class BankBot():
) )
else: else:
address = args[0] address = args[0]
this.client[address] = update.effective_chat.id
await context.bot.send_message( await context.bot.send_message(
chat_id=update.effective_chat.id, chat_id=update.effective_chat.id,
text=address text="已經設定 {} 的店家收款通知!"
) )
if __name__ == '__main__':
bot = BankBot()
bot.start_polling()

View File

@ -2,6 +2,7 @@ from flask import Flask, request, jsonify
import sqlite3 import sqlite3
import os import os
from flask_cors import CORS from flask_cors import CORS
from bot import BankBot
app = Flask(__name__) app = Flask(__name__)
CORS(app) CORS(app)
@ -165,9 +166,17 @@ def add_products(address):
(shop_id, product['name'], product['code'], product['price'])) (shop_id, product['name'], product['code'], product['price']))
db.commit() db.commit()
db.close() db.close()
return jsonify({'status': 'OK'}) return jsonify({'status': 'OK'})
if __name__ == '__main__': if __name__ == '__main__':
initDB() initDB()
app.run(host="0.0.0.0") app.run(host="0.0.0.0")
print("start the bot...")
bot = BankBot()
bot.start_polling()
bot.application.idle()

View File

@ -67,6 +67,7 @@ export default {
console.log(`Code matched = ${decodedText}`, decodedResult); console.log(`Code matched = ${decodedText}`, decodedResult);
if (decodedText in this.products){ if (decodedText in this.products){
var product = this.products[decodedText] var product = this.products[decodedText]
this.scanner.clear()
this.productCar.push({ this.productCar.push({
'name': product['name'], 'name': product['name'],
'id': product['id'], 'id': product['id'],
@ -74,10 +75,10 @@ export default {
'count': 1 'count': 1
}) })
} else { } else {
this.scanner.clear()
this.msg = "商品列表中沒有這項商品:"+decodedText this.msg = "商品列表中沒有這項商品:"+decodedText
this.warningModalStatus = true this.warningModalStatus = true
} }
this.scanner.clear()
}, },
scan() { scan() {
this.scanner = new Html5QrcodeScanner( this.scanner = new Html5QrcodeScanner(