1414import plugins .hato as hato
1515import plugins .analyze as analyze
1616from library .clientclass import SlackClient , ApiClient
17+ from library .database import Database
1718
1819app = Flask (__name__ )
1920
@@ -53,6 +54,32 @@ def on_app_mention(event_data):
5354 channel = event_data ["event" ]["channel" ]
5455 blocks = event_data ['event' ]['blocks' ]
5556 authed_users = event_data ['authed_users' ]
57+ client_msg_id = event_data ['event' ]['client_msg_id' ]
58+
59+ print (f'event_data: { event_data } ' )
60+ print (f'channel: { channel } ' )
61+ print (f'blocks: { blocks } ' )
62+ print (f'authed_users: { authed_users } ' )
63+ print (f'client_msg_id: { client_msg_id } ' )
64+
65+ with Database () as _db , _db .conn .cursor () as cursor :
66+ cursor .execute (
67+ 'SELECT client_msg_id FROM slack_client_msg_id WHERE client_msg_id = %s LIMIT 1' ,
68+ (client_msg_id ,))
69+
70+ if cursor .fetchone ():
71+ print ('skip' )
72+ return
73+
74+ cursor .execute (
75+ "DELETE FROM slack_client_msg_id "
76+ "WHERE created_at < CURRENT_TIMESTAMP - interval '10 minutes'" ,
77+ (client_msg_id ,))
78+ cursor .execute (
79+ 'INSERT INTO slack_client_msg_id(client_msg_id, created_at) '
80+ 'VALUES(%s, CURRENT_TIMESTAMP)' ,
81+ (client_msg_id ,))
82+ _db .conn .commit ()
5683
5784 with ThreadPoolExecutor (max_workers = 3 ) as tpe :
5885 for block in blocks :
@@ -68,11 +95,6 @@ def on_app_mention(event_data):
6895 SlackClient (channel ,
6996 block_element_elements [0 ]['user_id' ]))
7097
71- print (f'event_data: { event_data } ' )
72- print (f'channel: { channel } ' )
73- print (f'blocks: { blocks } ' )
74- print (f'authed_users: { authed_users } ' )
75-
7698
7799@app .route ("/" , methods = ["GET" , "POST" ])
78100def http_app ():
0 commit comments