Skip to content
This repository has been archived by the owner on Nov 26, 2018. It is now read-only.

Commit

Permalink
Add support for message service.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaker authored and vbabiy committed Jan 21, 2015
1 parent a62f7a5 commit 2e194d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
18 changes: 15 additions & 3 deletions botbot/apps/plugins/plugin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import logging
from botbot_plugins.base import PrivateMessage

LOG = logging.getLogger('botbot.plugin_runner')


class RealPluginMixin(object):
"""
All the things that need to get added to botbot-plugins
Expand Down Expand Up @@ -40,6 +42,11 @@ def retrieve(self, key):
LOG.info('Retrieved: %s=%s', key, value)
return value

def delete(self, key):
""" Delete the value from Redis"""
ukey = self.unique_key(key)
return self.app.storage.delete(ukey) == 1

def greenlet_respond(self, grnlt):
"""Callback for gevent return values"""
msg = grnlt.value
Expand All @@ -49,10 +56,15 @@ def respond(self, msg):
"""Writes message back to the channel the line was received on"""
# Internal method, not part of public API
if msg:
lines = msg.split('\n')
nick = self.channel_name
if isinstance(msg, PrivateMessage):
lines= msg.msg.split('\n')
nick = msg.nick
else:
lines = msg.split('\n')
for response_line in lines:
LOG.info('Write to %s: %s', self.channel_name, response_line)
LOG.info('Write to %s: %s', nick, response_line)
response_cmd = u'WRITE {0} {1} {2}'.format(self.chatbot_id,
self.channel_name,
nick,
response_line)
self.app.bot_bus.lpush('bot', response_cmd)
4 changes: 3 additions & 1 deletion botbot/apps/plugins/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import re
import redis
import botbot_plugins.plugins
from botbot_plugins.base import PrivateMessage
from django.core.cache import cache
from django.conf import settings
from django.utils.importlib import import_module
Expand All @@ -20,6 +21,7 @@
CACHE_TIMEOUT_2H = 7200
LOG = logging.getLogger('botbot.plugin_runner')


class Line(object):
"""
All the methods and data necessary for a plugin to act on a line
Expand Down Expand Up @@ -220,7 +222,7 @@ def dispatch(self, line):
if hasattr(self, 'gevent'):
self.gevent.Greenlet.spawn(new_func, line)
else:
new_func(line)
channel_plugin.respond(new_func(line))

# pass line to other routers
if line._is_message:
Expand Down

0 comments on commit 2e194d3

Please sign in to comment.