-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_oppai.py
34 lines (29 loc) · 1014 Bytes
/
main_oppai.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import oppai
import oppai.slack_ctrl as slack_ctrl
from slack_sdk.rtm_v2 import RTMClient
import re
if __name__ == '__main__':
data = oppai.Data("./data","./private")
bot = oppai.Bot(data)
auth_data = slack_ctrl.auth_load(data.conf['slack']['accessToken'])
# slack read
rtm = RTMClient(token=data.conf['slack']['accessToken'])
@rtm.on("message")
def slack_message_handle(client: RTMClient, event: dict):
channel_id = event['channel']
thread_ts = event['ts']
user = event['user']
if user == auth_data['user_id']:
return # self
if 'text' in event:
# input
text = event['text']
res = bot.incomming_message(channel_id,user,text)
if not res is None:
client.web_client.chat_postMessage(
channel=channel_id,
#thread_ts=thread_ts,
text=res,
as_user=True
)
rtm.start()