feat: trace TG client's following address

This commit is contained in:
Ting-Jun Wang 2023-06-14 00:07:18 +08:00
parent 49dcf1653e
commit f236aa0aed
Signed by: snsd0805
GPG Key ID: 8DB0D22BC1217D33
2 changed files with 22 additions and 9 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()