-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheeic_bot.py
31 lines (26 loc) · 906 Bytes
/
eeic_bot.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
#! /usr/bin/python3
# coding: utf-8
from slackclient import SlackClient
from slackbot.bot import Bot
import threading
class SlackBot:
def __init__(self, API_TOKEN):
self.client = SlackClient(API_TOKEN)
self.channel_list = self.getChannelList()
self.bot = Bot()
self.auto_replybot_thread = threading.Thread(target=self.bot.run, daemon=True) # メインスレッド終了時に終了するように
self.auto_replybot_thread.start()
def getChannelList(self):
channels = self.client.api_call("channels.list")
if channels['ok']:
return channels['channels']
else:
return None
def postMessage(self, channel_id, message: str):
ret = self.client.api_call(
"chat.postMessage",
channel=channel_id,
text=message,
as_user=True
)
return ret