Permalink
Browse files

Convert irc command to BaseCommand.

  • Loading branch information...
1 parent 7e39ec3 commit 2bd4fe23867b2dbe5f3b2ebce9e237db537cf626 @ralphbean committed Dec 4, 2012
Showing with 32 additions and 23 deletions.
  1. +28 −19 fedmsg/commands/ircbot.py
  2. +4 −4 fedmsg/consumers/ircbot.py
View
47 fedmsg/commands/ircbot.py
@@ -16,35 +16,44 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors: Ralph Bean <rbean@redhat.com>
+# Ryan Brown
#
# -*- coding; utf-8 -*-
-# Author: Ryan Brown
-# Description: A bot that takes a config and puts messages matching given
-# regexes in specified IRC channels. See fedmsg-config.py for options.
-from fedmsg.commands import command
+"""
+Description: A bot that takes a config and puts messages matching given
+regexes in specified IRC channels. See :term:`irc` for options.
+"""
+from fedmsg.commands import BaseCommand
from fedmsg.consumers.ircbot import IRCBotConsumer
-extra_args = []
-
-@command(name="fedmsg-irc", extra_args=extra_args, daemonizable=True)
-def ircbot(**kw):
+class IRCCommand(BaseCommand):
""" Relay messages from the bus to any number of IRC channels.
This is highly configurable by way of the :term:`irc` config value.
"""
- # Do just like in fedmsg.commands.hub and mangle fedmsg-config.py to work
- # with moksha's expected configuration.
- moksha_options = dict(
- zmq_subscribe_endpoints=','.join(
- ','.join(bunch) for bunch in kw['endpoints'].values()
- ),
- )
- kw.update(moksha_options)
+ name = "fedmsg-irc"
+ extra_args = []
+ daemonizable = True
+
+ def run(self):
+ # Do just like in fedmsg.commands.hub and mangle fedmsg-config.py to
+ # work with moksha's expected configuration.
+ moksha_options = dict(
+ zmq_subscribe_endpoints=','.join(
+ ','.join(bunch) for bunch in self.config['endpoints'].values()
+ ),
+ )
+ self.config.update(moksha_options)
+
+ self.config[IRCBotConsumer.config_key] = True
+
+ from moksha.hub import main
+ main(options=self.config, consumers=[IRCBotConsumer])
- kw[IRCBotConsumer.config_key] = True
- from moksha.hub import main
- main(options=kw, consumers=[IRCBotConsumer])
+def ircbot():
+ command = IRCCommand()
+ command.execute()
View
8 fedmsg/consumers/ircbot.py
@@ -41,6 +41,7 @@
from twisted.internet import defer
import logging
+log = logging.getLogger("moksha.hub")
mirc_colors = {
@@ -92,7 +93,6 @@ class FedMsngr(irc.IRCClient):
sourceURL = "http://github.com/ralphbean/fedmsg"
def __init__(self, *args, **kw):
- self.log = logging.getLogger("moksha.hub")
super(FedMsgnr, self).__init__(*args, **kw)
def _get_nickname(self):
@@ -104,16 +104,16 @@ def __init__(self, *args, **kwargs):
def signedOn(self):
self.join(self.factory.channel)
- self.log.info("Signed on as %s." % (self.nickname,))
+ log.info("Signed on as %s." % (self.nickname,))
def joined(self, channel):
- self.log.info("Joined %s." % (channel,))
+ log.info("Joined %s." % (channel,))
self.factory.parent_consumer.add_irc_client(self)
def got_modes(modelist):
modes = ''.join(modelist)
if 'c' in modes:
- self.log.info("%s has +c is on. No prettiness" % channel)
+ log.info("%s has +c is on. No prettiness" % channel)
self.factory.pretty = False
self.modes(channel).addCallback(got_modes)

0 comments on commit 2bd4fe2

Please sign in to comment.