Skip to content

Commit

Permalink
Using IRCHandler for toot commands
Browse files Browse the repository at this point in the history
  • Loading branch information
gagath committed Apr 28, 2017
1 parent 2555ae4 commit f55636f
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions hms_irc/commands/toot.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
import logging

from hms_irc import strings

from hms_irc.irc import IRCHandler

def get_logger():
return logging.getLogger(__name__)


def handle(irc_server, irc_chan, rabbit, command):
class TootHandler(IRCHandler):
def handle(self, command):
get_logger().info('Toot with command {}'.format(command))

# Define some useful closures
# TODO: Ugly way of testing command arguments...
if command.command_args and command.command_args[0]:
if command.is_voiced:
self.toot(' '.join(command.command_args))
self.chanmsg(strings.TOOT_PENDING)
else:
self.chanmsg(strings.TOOT_USAGE)

def toot(message):
def toot(self, msg):
"""Closure for sending a toot."""
rabbit.publish(
self.rabbit.publish(
'mastodon.toot', {
'message': message,
'message': msg,
'source': 'irc'
})

def chanmsg(msg):
"""Closure for sending a privmsg on the chan."""
irc_server.privmsg(irc_chan, msg)

get_logger().info('Toot with command {}'.format(command))

# TODO: Ugly way of testing command arguments...
if command.command_args and command.command_args[0]:
if command.is_voiced:
toot(' '.join(command.command_args))
chanmsg(strings.TOOT_PENDING)
else:
chanmsg(strings.TOOT_USAGE)
def handle(irc_server, irc_chan, rabbit, command):
h = TootHandler(irc_server, irc_chan, rabbit)
h.handle(command)

0 comments on commit f55636f

Please sign in to comment.