-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
17 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |