Skip to content

Commit

Permalink
Handling to provide echo of user message and handling unicode chars i…
Browse files Browse the repository at this point in the history
…n message strings. (#13)
randompi authored and mbrevoort committed Sep 15, 2016
1 parent e394fae commit 5f77301
Showing 3 changed files with 68 additions and 2 deletions.
62 changes: 62 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
venv/
.idea/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
*.pot

# Django stuff:
*.log

# Sphinx documentation
docs/_build/

# PyBuilder
target/

.DS_Store
plot.png
2 changes: 2 additions & 0 deletions bot/event_handler.py
Original file line number Diff line number Diff line change
@@ -48,5 +48,7 @@ def _handle_message(self, event):
self.msg_writer.write_joke(event['channel'])
elif 'attachment' in msg_txt:
self.msg_writer.demo_attachment(event['channel'])
elif 'echo' in msg_txt:
self.msg_writer.send_message(event['channel'], msg_txt)
else:
self.msg_writer.write_prompt(event['channel'])
6 changes: 4 additions & 2 deletions bot/messenger.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-

import logging
import random

@@ -12,9 +14,9 @@ def send_message(self, channel_id, msg):
# in the case of Group and Private channels, RTM channel payload is a complex dictionary
if isinstance(channel_id, dict):
channel_id = channel_id['id']
logger.debug('Sending msg: {} to channel: {}'.format(msg, channel_id))
logger.debug('Sending msg: %s to channel: %s' % (msg, channel_id))
channel = self.clients.rtm.server.channels.find(channel_id)
channel.send_message("{}".format(msg.encode('ascii', 'ignore')))
channel.send_message(msg)

def write_help_message(self, channel_id):
bot_uid = self.clients.bot_user_id()

0 comments on commit 5f77301

Please sign in to comment.