Skip to content

Instantly share code, notes, and snippets.

@ufian
Created Apr 20, 2017
Embed
What would you like to do?
diff --git a/bot/event_handler.py b/bot/event_handler.py
index 6f20bd2..31c8fb6 100644
--- a/bot/event_handler.py
+++ b/bot/event_handler.py
@@ -17,13 +17,14 @@ class RtmEventHandler(object):
def _handle_by_type(self, event_type, event):
# See https://api.slack.com/rtm for a full list of events
+ #logger.warning('Handle type {0} {1}'.format(event_type, event))
if event_type == 'error':
# error
self.msg_writer.write_error(event['channel'], json.dumps(event))
elif event_type == 'message':
# message was sent to channel
self._handle_message(event)
- elif event_type == 'channel_joined':
+ elif event_type == 'channel_joined' or event_type=='team_join':
# you joined a channel
self.msg_writer.write_help_message(event['channel'])
elif event_type == 'group_joined':
@@ -37,6 +38,13 @@ class RtmEventHandler(object):
if ('user' in event) and (not self.clients.is_message_from_me(event['user'])):
msg_txt = event['text']
+ #name = event.get('user_profile', {}).get('name', 'noname')
+
+ if 'leave' in event.get('subtype', ''):
+ self.msg_writer.write_leave(event['channel'], event['user'])
+
+ if 'join' in event.get('subtype', ''):
+ self.msg_writer.write_join(event['channel'],event['user'])
if self.clients.is_bot_mention(msg_txt) or self._is_direct_message(event['channel']):
# e.g. user typed: "@pybot tell me a joke!"
diff --git a/bot/messenger.py b/bot/messenger.py
index 6cacf9e..63f81a1 100644
--- a/bot/messenger.py
+++ b/bot/messenger.py
@@ -20,21 +20,36 @@ class Messenger(object):
def write_help_message(self, channel_id):
bot_uid = self.clients.bot_user_id()
- txt = '{}\n{}\n{}\n{}'.format(
- "I'm your friendly Slack bot written in Python. I'll *_respond_* to the following commands:",
- "> `hi <@" + bot_uid + ">` - I'll respond with a randomized greeting mentioning your user. :wave:",
- "> `<@" + bot_uid + "> joke` - I'll tell you one of my finest jokes, with a typing pause for effect. :laughing:",
- "> `<@" + bot_uid + "> attachment` - I'll demo a post with an attachment using the Web API. :paperclip:")
+ #txt = '{}\n{}\n{}\n{}'.format(
+ # "I'm your friendly Slack bot written in Python. I'll *_respond_* to the following commands:",
+ # "> `hi <@" + bot_uid + ">` - I'll respond with a randomized greeting mentioning your user. :wave:",
+ # "> `<@" + bot_uid + "> joke` - I'll tell you one of my finest jokes, with a typing pause for effect. :laughing:",
+ # "> `<@" + bot_uid + "> attachment` - I'll demo a post with an attachment using the Web API. :paperclip:")
+ txt = u"Что такое интеграл?"
self.send_message(channel_id, txt)
def write_greeting(self, channel_id, user_id):
- greetings = ['Hi', 'Hello', 'Nice to meet you', 'Howdy', 'Salutations']
- txt = '{}, <@{}>!'.format(random.choice(greetings), user_id)
+ #greetings = ['Hi', 'Hello', 'Nice to meet you', 'Howdy', 'Salutations']
+ #txt = '{}, <@{}>!'.format(random.choice(greetings), user_id)
+ txt = u"Что такое логарифм?"
+ self.send_message(channel_id, txt)
+
+ def write_leave(self, channel_id, user_id):
+ #greetings = ['Hi', 'Hello', 'Nice to meet you', 'Howdy', 'Salutations']
+ #txt = '{}, <@{}>!'.format(random.choice(greetings), user_id)
+ txt = u"<@{0}> так и не узнал что такое логарифм".format(user_id)
+ self.send_message(channel_id, txt)
+
+ def write_join(self, channel_id, user_id):
+ #greetings = ['Hi', 'Hello', 'Nice to meet you', 'Howdy', 'Salutations']
+ #txt = '{}, <@{}>!'.format(random.choice(greetings), user_id)
+ txt = u"<@{0}>, что такое интеграл?".format(user_id)
self.send_message(channel_id, txt)
def write_prompt(self, channel_id):
bot_uid = self.clients.bot_user_id()
txt = "I'm sorry, I didn't quite understand... Can I help you? (e.g. `<@" + bot_uid + "> help`)"
+ txt = u"Зачем это?"
self.send_message(channel_id, txt)
def write_joke(self, channel_id):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment