telegram_get_gmgnalertbot_sol.py 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. import time
  2. import asyncio
  3. from telethon import TelegramClient, events
  4. from telethon.errors.rpcerrorlist import AuthKeyError
  5. from telethon.sync import TelegramClient as SyncTelegramClient
  6. import json
  7. import datetime
  8. import signal
  9. import sys
  10. import math
  11. import requests
  12. from telethon.tl.types import MessageEntityTextUrl
  13. from apscheduler.schedulers.background import BackgroundScheduler
  14. from telethon.tl.types import PeerUser, PeerChat, PeerChannel
  15. import os
  16. import traceback
  17. import re
  18. from apscheduler.schedulers.asyncio import AsyncIOScheduler
  19. import pathlib
  20. import shutil
  21. import pandas as pd
  22. old_print = print
  23. def timestamped_print(*args, **kwargs):
  24. old_print(datetime.datetime.utcnow().replace(
  25. microsecond=0), *args, **kwargs)
  26. print = timestamped_print
  27. print('\n'*5)
  28. def global_exception_hook(exc_type, exc_value, exc_traceback):
  29. print(f"Global exception: {exc_type.__name__} - {exc_value}")
  30. traceback.print_tb(exc_traceback)
  31. raise
  32. def keep_alnum_forgmgn(string):
  33. return re.sub(r'[^a-zA-Z0-9\.\s\+\-]', ' ', string)
  34. def keep_alnum(string):
  35. return re.sub(r'[^a-zA-Z0-9\.\s:+-]', ' ', string)
  36. def term_sig_handler(signum, frame):
  37. # save_obj_unraydium_token()
  38. print(f'catched singal: {signum}')
  39. sys.exit()
  40. def global_exception_hook(exc_type, exc_value, exc_traceback):
  41. print(f"Global exception: {exc_type.__name__} - {exc_value}")
  42. traceback.print_tb(exc_traceback)
  43. raise
  44. int_pattern = r"^\d+$"
  45. api_id_gate = 29760088
  46. api_hash_gate = "7cd2222e0629c770789f9c6cf280d051"
  47. GMGN_Alert_Bot_Solana_id = 6917338381
  48. # ID: 7290510619, Name: GMGN Alert Bot - ETH, title: GMGN Alert Bot - ETH,
  49. # ID: 6917338381, Name: GMGN Alert Bot - Solana, title: GMGN Alert Bot - Solana,
  50. feishu_url = 'https://open.feishu.cn/open-apis/bot/v2/hook/a68cffbf-9104-427b-8e25-62dfaf363a47'
  51. utc_plus_8 = datetime.timezone(datetime.timedelta(hours=8))
  52. client_gate = TelegramClient('anon_gate', api_id_gate, api_hash_gate)
  53. client_gate.start()
  54. set_has_read_file=set()
  55. obj_queueing_send_feishu={
  56. # "feishu_timestamp":{
  57. # "is_sending":False,
  58. # "str_tokenaddress":str_tokenaddress,
  59. # "str_now_price":str_now_price,
  60. # "number_open":number_open,
  61. # "number_liq":number_liq,
  62. # "number_holders":number_holders,
  63. # "number_top_10_holding":number_top_10_holding,
  64. # "last_5m_change":last_5m_change,
  65. # "last_1h_change":last_1h_change,
  66. # "feishu_timestamp":cur_now_timestamp,
  67. # }
  68. }
  69. async def ready_send_feishu(obj_temp_queueing_send_feishu):
  70. global obj_queueing_send_feishu , utc_plus_8
  71. cur_now_timestamp = int(time.time()*1000)
  72. arr_send_feishu_info = []
  73. for obj_one_queueing_send_feishu in obj_temp_queueing_send_feishu.values():
  74. str_tokenaddress = obj_one_queueing_send_feishu["str_tokenaddress"]
  75. feishu_timestamp = obj_one_queueing_send_feishu["feishu_timestamp"]
  76. if obj_one_queueing_send_feishu["is_sending"] == True:
  77. if cur_now_timestamp - obj_one_queueing_send_feishu["sending_time"] >=obj_one_queueing_send_feishu["send_counts"]* 15*1000:
  78. print(f"feishu_timestamp={feishu_timestamp} str_tokenaddress={str_tokenaddress} is_sending_too_long del")
  79. del obj_queueing_send_feishu[feishu_timestamp]
  80. else:
  81. print(f"feishu_timestamp={feishu_timestamp} str_tokenaddress={str_tokenaddress} is_sending")
  82. return True
  83. obj_one_queueing_send_feishu["sending_time"] = cur_now_timestamp
  84. obj_one_queueing_send_feishu["send_counts"]+=1
  85. obj_one_queueing_send_feishu["is_sending"] = True
  86. # 将时间戳转换为datetime对象,并指定时区 ,转换为ISO 8601格式的时间字符串,包含时区信息
  87. str_iso8601_date = datetime.datetime.fromtimestamp(feishu_timestamp/1000, tz=utc_plus_8).isoformat().split('.')[0]
  88. str_now_price = obj_one_queueing_send_feishu["str_now_price"]
  89. str_dev_status = obj_one_queueing_send_feishu["str_dev_status"]
  90. str_swap_type = obj_one_queueing_send_feishu["str_swap_type"]
  91. str_swap_token_amount = str(obj_one_queueing_send_feishu["number_swap_token_amount"] )
  92. str_swap_sol = str(obj_one_queueing_send_feishu["number_swap_sol"])
  93. str_dalaoaddress = obj_one_queueing_send_feishu["str_dalaoaddress"]
  94. str_last_5m_change = str(obj_one_queueing_send_feishu["last_5m_change"])
  95. str_last_1h_change = str(obj_one_queueing_send_feishu["last_1h_change"])
  96. str_number_holders = str(obj_one_queueing_send_feishu["number_holders"])
  97. str_number_liq_sol = str(obj_one_queueing_send_feishu["number_liq_sol"])
  98. str_number_open = ""
  99. if obj_one_queueing_send_feishu["number_open"] >24:
  100. str_number_open = str(obj_one_queueing_send_feishu["number_open"]/24) + "d"
  101. else:
  102. str_number_open = str(obj_one_queueing_send_feishu["number_open"]) + "h"
  103. arr_send_feishu_info.append( {
  104. "str_iso8601_date": str_iso8601_date,
  105. "str_tokenaddress":str_tokenaddress,
  106. "str_dalaoaddress":str_dalaoaddress,
  107. "str_dev_status":str_dev_status,
  108. "str_swap_type":str_swap_type,
  109. "str_number_liq_sol":str_number_liq_sol,
  110. "str_swap_token_amount":str_swap_token_amount,
  111. "str_swap_sol":str_swap_sol,
  112. "str_number_holders":str_number_holders,
  113. "str_last_5m_change":str_last_5m_change,
  114. "str_last_1h_change":str_last_1h_change,
  115. "str_now_price": str_now_price,
  116. "str_number_open":str_number_open,
  117. })
  118. # 发给飞书
  119. send_feishu(
  120. arr_send_feishu_info
  121. )
  122. for obj_one_queueing_send_feishu in obj_temp_queueing_send_feishu.values():
  123. str_tokenaddress = obj_one_queueing_send_feishu["str_tokenaddress"]
  124. feishu_timestamp = obj_one_queueing_send_feishu["feishu_timestamp"]
  125. del obj_queueing_send_feishu[feishu_timestamp]
  126. return
  127. def send_feishu(arr_obj_sendmsg):
  128. payload_message = {
  129. "msg_type": "post",
  130. "content": {
  131. "post": {
  132. "zh_cn": {
  133. "title": arr_obj_sendmsg[0]["str_iso8601_date"],
  134. "content": [
  135. ]
  136. }
  137. }
  138. }
  139. }
  140. headers = {
  141. "Content-Type": "application/json; charset=utf-8",
  142. }
  143. content = []
  144. for obj_sendmsg in arr_obj_sendmsg:
  145. content.append([
  146. {
  147. "tag": "text",
  148. 'text': obj_sendmsg['str_swap_type']
  149. } ,
  150. {
  151. "tag": "text",
  152. 'text': ' '+obj_sendmsg['str_tokenaddress']
  153. }
  154. ])
  155. content.append([
  156. {
  157. "tag": "text",
  158. 'text': "dalao: "+ obj_sendmsg['str_dalaoaddress']
  159. } ,
  160. {
  161. "tag": "text",
  162. 'text': ' ' + obj_sendmsg['str_swap_token_amount'] + 'tokens' ,
  163. } ,
  164. {
  165. "tag": "text",
  166. 'text': ' ' + obj_sendmsg['str_swap_sol'] +'sol'
  167. } ,
  168. ])
  169. content.append([
  170. {
  171. "tag": "text",
  172. 'text': "liq: " + obj_sendmsg['str_number_liq_sol']
  173. } ,
  174. {
  175. "tag": "text",
  176. 'text': ' op:' + obj_sendmsg['str_number_open']
  177. }
  178. ,
  179. {
  180. "tag": "text",
  181. 'text': ' dev:' + obj_sendmsg['str_dev_status']
  182. }
  183. ])
  184. content.append([
  185. {
  186. "tag": "text",
  187. 'text': "price:" + obj_sendmsg['str_now_price']
  188. },
  189. {
  190. "tag": "text",
  191. 'text': ' ho:' + obj_sendmsg["str_number_holders"]
  192. }
  193. ])
  194. content.append([
  195. {
  196. "tag": "text",
  197. 'text': "5m: " + obj_sendmsg['str_last_5m_change'] + "%"
  198. },
  199. {
  200. "tag": "text",
  201. 'text': ' 1h: ' + obj_sendmsg["str_last_1h_change"] + "%"
  202. }
  203. ])
  204. content.append([{
  205. "tag": "a",
  206. "href": "https://gmgn.ai/sol/token/" + obj_sendmsg["str_tokenaddress"],
  207. "text": "GMGN " + obj_sendmsg["str_tokenaddress"][-6:]
  208. }])
  209. content.append([{
  210. "tag": "a",
  211. "href": "https://dexscreener.com/solana/" + obj_sendmsg["str_tokenaddress"] + "?maker=" +obj_sendmsg["str_dalaoaddress"],
  212. "text": "DEX " + obj_sendmsg["str_tokenaddress"][-6:]
  213. }])
  214. content.append([{
  215. "tag": "text",
  216. "text": "*****************"
  217. }])
  218. content.append([{
  219. "tag": "at",
  220. "user_id": "all",
  221. "user_name": "allman"
  222. }])
  223. payload_message["content"]["post"]["zh_cn"]["content"] = content
  224. payload_message["content"] = json.dumps(payload_message["content"])
  225. payload_message = json.dumps(payload_message)
  226. response = requests.post(
  227. url=feishu_url, headers=headers, data=payload_message)
  228. # response_json = response.json()
  229. # print("response_json=",response_json)
  230. return
  231. async def ready_send_feishu_timed():
  232. global obj_queueing_send_feishu
  233. if len(obj_queueing_send_feishu.keys())==0:
  234. return
  235. arr_feishu_timestamp = (list(obj_queueing_send_feishu.keys()))
  236. obj_temp_queueing_send_feishu = {}
  237. for feishu_timestamp in arr_feishu_timestamp:
  238. obj_temp_queueing_send_feishu[feishu_timestamp] = (obj_queueing_send_feishu[feishu_timestamp])
  239. handle_res = await ready_send_feishu(obj_temp_queueing_send_feishu=obj_temp_queueing_send_feishu )
  240. return
  241. obj_queueing_tokenaddress={}
  242. address_pattern = re.compile(r'^[a-zA-Z0-9]+$')
  243. def check_is_address(string):
  244. if address_pattern.match(string):
  245. return True
  246. else:
  247. return False
  248. @client_gate.on(events.NewMessage(chats=[GMGN_Alert_Bot_Solana_id ], incoming=True))
  249. async def handle_incoming_GMGN_bot_NewMessage(event):
  250. global obj_queueing_tokenaddress
  251. event_message = event.message
  252. message_text = event.message.message
  253. # print("enter handle_incoming_GMGN_bot_NewMessage client_gate.on(events.NewMessage event_message=",event_message)
  254. print("enter handle_incoming_GMGN_bot_NewMessage client_gate.on(events.NewMessage message_text=",message_text)
  255. # return
  256. swap_buttons = event.message.buttons
  257. if not swap_buttons:
  258. print("GMGN_Alert_Bot_Solana_id not buttons")
  259. return
  260. swap_buttons = sum(swap_buttons, [])
  261. button_chart_line = swap_buttons[0]
  262. url_chart_line = button_chart_line.url
  263. if url_chart_line is None:
  264. print("url_chart_line is Nnoe")
  265. return
  266. arr_url_chart_line = url_chart_line.split("?wallet=")
  267. str_dalaoaddress = arr_url_chart_line[-1]
  268. str_tokenaddress = arr_url_chart_line[0].split("/")[-1]
  269. # 🔴4632BM....BMA7Z sell 2.12 SOL WeCat PnL+7.46% on Raydium 🔴🔴🔴🔴
  270. # [Sell all] Check tx
  271. # 🪙Buy: $310.59(2.12 SOL)/ 3.4M
  272. # 💲Price/Avg Cost: $0.00009/$0.00008
  273. # 🚀Total Profit: 🟢+$21.57(+7.46%)
  274. # 💎Current Holdings: --
  275. # 💰Total buy: $289.02(1.98 SOL)/ 3.4M 1 TXs
  276. # 💳Total sell: $310.59(2.12 SOL)/ 3.4M 1 TXs
  277. # ⏳SOL Balance: 20.86 SOL
  278. # $WeCat(WeCat 微猫)
  279. # EAMU6WF4SzcWaVEPf6q6YmG7tsaC5jtmjXFWyjorpump
  280. # 📈 5m | 1h | 6h: 53.95% | 2013.3% | 2013.3%
  281. # 🎲 5m TXs/Vol: 855/$136.6K
  282. # 💡 MCP: $90.6K
  283. # 💧 Liq: 100.71 SOL ($29.4K 🔥99.98%)
  284. # 👥 Holder: 466
  285. # 🕒 Open: 4min ago
  286. # ✅NoMint / ✅Blacklist / ✅Burnt
  287. # ✅TOP 10: 19.37%<30%
  288. # ⏳ DEV: 🚨 Sell All
  289. # 👨‍🍳 DEV Burnt烧币: -
  290. # 🌏 Website | 💊️ Pump
  291. # 🌈Push Smart Money Alerts in group? Invite @Alert_GMGNBOT in your group
  292. # 💎 NEW: 100x MEME & Smart Money Hunter with GMGN.ai
  293. str_now_price = None
  294. str_swap_type = None
  295. last_5m_change = None
  296. last_1h_change = None
  297. number_open = 0
  298. number_liq_sol = 0
  299. nomint_flag = False
  300. blacklist_flag = False
  301. burnt_flag = False
  302. number_insiders = 0
  303. number_holders = 0
  304. dev_action = None
  305. is_normal = True
  306. number_swap_token_amount = 0
  307. number_swap_sol = 0
  308. str_dev_status = "unknown"
  309. top_10_flag = False
  310. message_text=message_text.lower()
  311. message_text=message_text.strip()
  312. arr_total_split_message = re.split('\n+', message_text)
  313. for idx,split_message in enumerate( arr_total_split_message):
  314. split_message=split_message.strip()
  315. if idx == 0 and "...." in split_message:
  316. if "on raydium" not in split_message:
  317. print("platform is not raydium")
  318. return
  319. if "🔴" in split_message:
  320. str_swap_type = "sell"
  321. elif "🟢" in split_message:
  322. str_swap_type = "buy"
  323. continue
  324. elif "🪙buy:" in split_message :
  325. # 获取当前 购买/卖出的sol 与 token 数量
  326. split_message = keep_alnum_forgmgn(split_message)
  327. split_message=split_message.replace("--","0")
  328. if str_swap_type=="buy":
  329. if "sol" not in split_message:
  330. print(f"{str_swap_type} no sol amount")
  331. return
  332. split_message=split_message.strip()
  333. split_message=split_message.replace("sol","")
  334. split_message = re.sub(r"\s+", " ", split_message)
  335. arr_split_message = split_message.split(' ')
  336. split_message_token_amount = arr_split_message[-1]
  337. split_message_sol = arr_split_message[-2]
  338. number_swap_sol = float(split_message_sol)
  339. base_amount = 1
  340. if "m" in split_message_token_amount:
  341. split_message_token_amount =split_message_token_amount.replace("m","")
  342. base_amount = 10**6
  343. elif "k" in split_message_token_amount:
  344. split_message_token_amount =split_message_token_amount.replace("k","")
  345. base_amount = 10**3
  346. elif "b" in split_message_token_amount:
  347. split_message_token_amount =split_message_token_amount.replace("b","")
  348. base_amount = 10**9
  349. number_swap_token_amount = int(base_amount * float(split_message_token_amount) )
  350. elif "💲price" in split_message :
  351. # 获取当前价格
  352. split_message=split_message.replace("--","0")
  353. split_message=split_message.replace("/"," ")
  354. temp_now_price = None
  355. if "💲price:" in split_message:
  356. temp_now_price = split_message.split(" ")[-1]
  357. elif "💲price avg" in split_message:
  358. temp_now_price = split_message.split(" ")[-2]
  359. temp_now_price=temp_now_price.replace("$","")
  360. arr_temp_now_price = temp_now_price.split(".")
  361. integer_now_price = arr_temp_now_price[0]
  362. fractional_now_price = arr_temp_now_price[1]
  363. if "{" in fractional_now_price:
  364. fractional_now_price = re.sub(r"[{}]", " ", fractional_now_price)
  365. arr_fractional_now_price = fractional_now_price.split(" ")
  366. fractional_now_price = "0" * (int(arr_fractional_now_price[-2]))+ arr_fractional_now_price[-1]
  367. str_now_price = integer_now_price + "." + fractional_now_price
  368. elif "1h" in split_message :
  369. # 获取最近时间的价格变化
  370. # split_message = re.sub(r"[|%:📈]", "", split_message)
  371. # split_message = re.sub(r"\s+", " ", split_message)
  372. split_message = keep_alnum_forgmgn(split_message)
  373. split_message = re.sub(r"\s+", " ", split_message)
  374. split_message=split_message.strip()
  375. arr_price_change = split_message.split(" ")
  376. if len(arr_price_change)==6:
  377. last_5m_change = arr_price_change[3]
  378. last_1h_change = arr_price_change[4]
  379. elif "liq:" in split_message:
  380. split_message=split_message.replace("sol","")
  381. split_message=split_message.replace(",","")
  382. split_message = keep_alnum_forgmgn(split_message)
  383. split_message=split_message.strip()
  384. split_message = re.sub(r"\s+", " ", split_message)
  385. arr_split_message = split_message.split(' ')
  386. split_message_sol = arr_split_message[1]
  387. number_liq_sol = float(split_message_sol)
  388. elif "holder:" in split_message:
  389. split_message = keep_alnum_forgmgn(split_message)
  390. split_message=split_message.strip()
  391. split_message = re.sub(r"\s+", " ", split_message)
  392. arr_split_message = split_message.split(' ')
  393. number_holders = int(arr_split_message[1])
  394. elif "open" in split_message:
  395. split_message = keep_alnum_forgmgn(split_message)
  396. split_message=split_message.strip()
  397. split_message = re.sub(r"\s+", " ", split_message)
  398. arr_split_message = split_message.split(' ')
  399. if "d" in arr_split_message[1]:
  400. number_open = int(arr_split_message[1].replace("d","")) *24
  401. elif "h" in arr_split_message[1]:
  402. number_open = int(arr_split_message[1].replace("h",""))
  403. elif "min" in arr_split_message[1]:
  404. number_open = round(int(arr_split_message[1].replace("min","")) / 60 , 2 )
  405. elif "nomint" in split_message:
  406. split_message =split_message.replace("✅","yes ")
  407. split_message =split_message.replace("❌","no ")
  408. split_message =split_message.replace("?","no ")
  409. split_message = keep_alnum_forgmgn(split_message)
  410. split_message=split_message.strip()
  411. split_message = re.sub(r"\s+", " ", split_message)
  412. arr_split_message = split_message.split(' ')
  413. nomint_flag = (arr_split_message[0]=="yes")
  414. blacklist_flag = (arr_split_message[2]=="yes")
  415. burnt_flag = (arr_split_message[4]=="yes")
  416. elif "top 10:" in split_message:
  417. split_message =split_message.replace("✅","yes ")
  418. split_message =split_message.replace("❌","no ")
  419. split_message =split_message.replace("?","no ")
  420. split_message = keep_alnum_forgmgn(split_message)
  421. split_message=split_message.strip()
  422. split_message = re.sub(r"\s+", " ", split_message)
  423. arr_split_message = split_message.split(' ')
  424. top_10_flag = (arr_split_message[0]=="yes")
  425. elif "⏳ dev:" in split_message:
  426. split_message = keep_alnum_forgmgn(split_message)
  427. split_message=split_message.replace("--","0")
  428. split_message=split_message.strip()
  429. if "hold" in split_message:
  430. str_dev_status = "hold"
  431. elif "sell all" in split_message:
  432. str_dev_status = "unhold"
  433. elif "buy more" in split_message:
  434. str_dev_status = "hold"
  435. if (nomint_flag and blacklist_flag and burnt_flag ) == False:
  436. is_normal = False
  437. if number_liq_sol <= 10:
  438. # 1 sol = 150 $
  439. is_normal =False
  440. if top_10_flag == False:
  441. is_normal = False
  442. if number_holders <= 60 :
  443. is_normal =False
  444. print("info=",{
  445. "nomint_flag":nomint_flag,
  446. "blacklist_flag":blacklist_flag,
  447. "burnt_flag":burnt_flag,
  448. "top_10_flag":top_10_flag,
  449. "str_dev_status":str_dev_status,
  450. "str_swap_type":str_swap_type,
  451. "str_tokenaddress":str_tokenaddress,
  452. "str_dalaoaddress":str_dalaoaddress,
  453. "str_swap_type":str_swap_type,
  454. "number_swap_sol":number_swap_sol,
  455. "number_swap_token_amount":number_swap_token_amount,
  456. "str_now_price":str_now_price,
  457. "number_open":number_open,
  458. "number_liq_sol":number_liq_sol,
  459. "number_holders":number_holders,
  460. "last_5m_change":last_5m_change,
  461. "last_1h_change":last_1h_change,
  462. }
  463. )
  464. if is_normal ==False:
  465. print(f"{str_tokenaddress} is unnormal")
  466. return
  467. else:
  468. print(f"{str_tokenaddress} is normal")
  469. global obj_queueing_send_feishu
  470. cur_now_timestamp = int(time.time()*1000)
  471. obj_queueing_send_feishu[cur_now_timestamp] = {
  472. "is_sending":False,
  473. "send_counts":0,
  474. "sending_time":0,
  475. "str_dev_status":str_dev_status,
  476. "str_tokenaddress":str_tokenaddress,
  477. "str_dalaoaddress":str_dalaoaddress,
  478. "str_swap_type":str_swap_type,
  479. "number_swap_sol":number_swap_sol,
  480. "number_swap_token_amount":number_swap_token_amount,
  481. "str_now_price":str_now_price,
  482. "number_open":number_open,
  483. "number_liq_sol":number_liq_sol,
  484. "number_holders":number_holders,
  485. "last_5m_change":last_5m_change,
  486. "last_1h_change":last_1h_change,
  487. "feishu_timestamp":cur_now_timestamp,
  488. }
  489. return
  490. obj_global_info ={
  491. "timedTasks_idx":0
  492. }
  493. sys.excepthook = global_exception_hook
  494. signal.signal(signal.SIGTERM, term_sig_handler)
  495. signal.signal(signal.SIGINT, term_sig_handler)
  496. print(f"Begin Listening for messages containing in chats ichat names...")
  497. async def timedTasks():
  498. global obj_global_info
  499. obj_global_info["timedTasks_idx"]+=1
  500. cur_timedTasks_idx =obj_global_info["timedTasks_idx"]
  501. if cur_timedTasks_idx <5:
  502. return
  503. if cur_timedTasks_idx%3609 == 0:
  504. obj_global_info["timedTasks_idx"]=10
  505. if cur_timedTasks_idx%10==0:
  506. # 10s一次飞书
  507. await ready_send_feishu_timed()
  508. return
  509. # scheduler = BackgroundScheduler({'apscheduler.timezone': 'UTC'})
  510. scheduler = AsyncIOScheduler({'apscheduler.timezone': 'UTC'})
  511. scheduler.add_job(timedTasks, "interval", seconds=1)
  512. # scheduler.add_job(func=timedTasks, trigger="cron", seconds=10)
  513. # '*/1 * * * * *'
  514. scheduler.start()
  515. client_gate.run_until_disconnected()
  516. asyncio.get_event_loop().run_forever()