Skip to content

Commit

Permalink
Convert irc command to BaseCommand.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed Dec 4, 2012
1 parent 7e39ec3 commit 2bd4fe2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
47 changes: 28 additions & 19 deletions fedmsg/commands/ircbot.py
Expand Up @@ -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()
8 changes: 4 additions & 4 deletions fedmsg/consumers/ircbot.py
Expand Up @@ -41,6 +41,7 @@
from twisted.internet import defer

import logging
log = logging.getLogger("moksha.hub")


mirc_colors = {
Expand Down Expand Up @@ -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):
Expand All @@ -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)

Expand Down

0 comments on commit 2bd4fe2

Please sign in to comment.