Skip to content

Commit fcddf7d

Browse files
committed
fix: 修复 tg bot
1 parent e805d5e commit fcddf7d

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

tgbot/app.py

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,17 @@ def build_message(data: dict):
104104

105105
async def get_latest_message() -> dict | None:
106106
message = await tg_bot.pop_message(my_chat_id)
107+
"""
108+
(b'tgbot:5049063827', b'{"address": "EARFf4ZxBRBuPJc1DyhNwXG5GJNJYSEZHNUJwTSGhzyQ", "token_mint": "Gc2yDSR1rUZ4QuWc4yxQ3y7cvAA2AE2QmrjP3a8mpump", "token_amount": 12.85346999997273, "pre_token_balance": 283068.032564, "post_token_balance": 283055.179094, "transaction_type": "reduce", "transaction_id": "EARFf4ZxBRBuPJc1DyhNwXG5GJNJYSEZHNUJwTSGhzyQ:Gc2yDSR1rUZ4QuWc4yxQ3y7cvAA2AE2QmrjP3a8mpump:12.85346999997273:reduce", "signature": "42GPWM2XNtAdJBmuyX6owbjRK9Ej2MnkqDKP1K4mSaMgeqYnQ8S11T2MmszkHHNSx9ifnXiPCVgSkc44qVZRbotz"}')
109+
"""
107110
if message is None:
108111
return
109-
assert isinstance(message, bytes)
110-
data = json.loads(message.decode("utf-8"))
112+
_, content = message
113+
try:
114+
data = json.loads(content.decode("utf-8"))
115+
except json.JSONDecodeError:
116+
logger.error(f"Failed to decode message: {content}")
117+
return
111118
return data
112119

113120

@@ -161,7 +168,7 @@ async def func(bot):
161168
logger.info("Checking for new messages...")
162169
data = await get_latest_message()
163170
if data is None:
164-
return
171+
continue
165172
await send_message(bot, my_chat_id, data)
166173

167174

@@ -186,19 +193,17 @@ async def func(bot):
186193

187194

188195
def main() -> None:
189-
# 替换 'YOUR_TOKEN' 为你的机器人 API Token
190-
application = ApplicationBuilder().token(tg_bot_token).build()
191-
bot = application.bot
192-
193-
# 注册处理程序
194-
# application.add_handler(CommandHandler("start", start))
195-
# application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
196-
197-
loop = asyncio.new_event_loop()
198-
loop.run_until_complete(func(bot))
199-
200-
# 启动机器人
201-
application.run_polling()
196+
# application = ApplicationBuilder().token(tg_bot_token).build()
197+
# bot = application.bot
198+
#
199+
# # 注册处理程序
200+
# # application.add_handler(CommandHandler("start", start))
201+
# # application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
202+
#
203+
# application.create_task(func(bot))
204+
# application.run_polling()
205+
bot = Bot(token=tg_bot_token)
206+
asyncio.run(func(bot))
202207

203208

204209
if __name__ == "__main__":

0 commit comments

Comments
 (0)