From 3e63c2e458bcfb4bec59db00397e284efeb567c1 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Thu, 17 Feb 2011 12:31:51 -0600 Subject: [PATCH] since sending arbitrary text and replying now have very different goals, add Module.sendmsg this just sends a privmsg to the specified target on the specified connection. pretty straightforward. also, update the modules that need it to use it. --- Module.py | 9 +++++++++ modules/Storycraft.py | 12 ++++++------ modules/Twitter.py | 4 ++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Module.py b/Module.py index b21e331..f3036cd 100644 --- a/Module.py +++ b/Module.py @@ -131,6 +131,15 @@ class Module(object): if stop_responding: return "NO MORE" + def sendmsg(self, connection, target, msg): + """Send a privmsg over IRC to target.""" + + if msg is not None: + if target is not None: + msgs = msg.split('\n') + for line in msgs: + connection.privmsg(target, line) + def save(self): """Save whatever the module may need to save. Sync files, etc. diff --git a/modules/Storycraft.py b/modules/Storycraft.py index c0f75e7..ccf181d 100644 --- a/modules/Storycraft.py +++ b/modules/Storycraft.py @@ -250,7 +250,7 @@ class Storycraft(Module): self._add_player_to_game(game_id, nick, userhost) # tell the control channel - self.irc.reply(connection, master_channel, '{0:s} created a game of storycraft - do \'!storycraft join game {1:d}\' to take part!'.format(nick, game_id)) + self.sendmsg(connection, master_channel, '{0:s} created a game of storycraft - do \'!storycraft join game {1:d}\' to take part!'.format(nick, game_id)) return 'Game #{0:d} has been created. When everyone has joined, do \'!storycraft start game {0:d}\''.format(game_id) else: @@ -280,7 +280,7 @@ class Storycraft(Module): settings = self._get_storycraft_settings() master_channel = settings.master_channel - self.irc.reply(connection, master_channel, '{0:s} joined storycraft #{1:d}!'.format(nick, game_id)) + self.sendmsg(connection, master_channel, '{0:s} joined storycraft #{1:d}!'.format(nick, game_id)) return '{0:s}, welcome to the game.'.format(nick) else: return 'Error joining game.' @@ -352,7 +352,7 @@ class Storycraft(Module): master_channel = settings.master_channel # tell the control channel - self.irc.reply(connection, master_channel, '{0:s} started storycraft #{1:d}! - first player is {2:s}, do \'!storycraft game {1:d} show line\' when the game is assigned to you.'.format(nick, game_id, player.nick)) + self.sendmsg(connection, master_channel, '{0:s} started storycraft #{1:d}! - first player is {2:s}, do \'!storycraft game {1:d} show line\' when the game is assigned to you.'.format(nick, game_id, player.nick)) return 'Game #{0:d} started.'.format(game_id) else: @@ -453,7 +453,7 @@ class Storycraft(Module): return_msg = 'Line logged. Please add another. ' + progress_str else: # notify the new owner, too - self.irc.reply(connection, player.nick, 'You have a new line in storycraft #{0:d}: \'{1:s}\' {2:s}'.format(game_id, last_line.line, progress_str)) + self.sendmsg(connection, player.nick, 'You have a new line in storycraft #{0:d}: \'{1:s}\' {2:s}'.format(game_id, last_line.line, progress_str)) # get the default settings settings = self._get_storycraft_settings() @@ -461,10 +461,10 @@ class Storycraft(Module): # log output if game.status == 'IN PROGRESS': - self.irc.reply(connection, master_channel, '{0:s} added a line to storycraft #{1:d}! - next player is {2:s}'.format(nick, game_id, player.nick)) + self.sendmsg(connection, master_channel, '{0:s} added a line to storycraft #{1:d}! - next player is {2:s}'.format(nick, game_id, player.nick)) return return_msg else: - self.irc.reply(connection, master_channel, '{0:s} finished storycraft #{1:d}!'.format(nick, game_id)) + self.sendmsg(connection, master_channel, '{0:s} finished storycraft #{1:d}!'.format(nick, game_id)) return 'Line logged (and game completed).' else: return 'Failed to assign game to next player.' diff --git a/modules/Twitter.py b/modules/Twitter.py index 413b30f..1de7f15 100644 --- a/modules/Twitter.py +++ b/modules/Twitter.py @@ -245,7 +245,7 @@ class Twitter(Module): tweets = self.twit.GetFriendsTimeline(since_id=since_id) for tweet in tweets: tweet_text = self._return_tweet_or_retweet_text(tweet=tweet, print_source=True) - self.irc.reply(self.connection, output_channel.encode('utf-8', 'ignore'), tweet_text) + self.sendmsg(self.connection, output_channel.encode('utf-8', 'ignore'), tweet_text) # friends timeline printed, find the latest id new_since_id = self._get_latest_tweet_id(tweets, since_id) @@ -253,7 +253,7 @@ class Twitter(Module): tweets = self.twit.GetMentions(since_id=since_id) for tweet in tweets: tweet_text = self._return_tweet_or_retweet_text(tweet=tweet, print_source=True) - self.irc.reply(self.connection, output_channel.encode('utf-8', 'ignore'), tweet_text) + self.sendmsg(self.connection, output_channel.encode('utf-8', 'ignore'), tweet_text) # mentions printed, find the latest id new_since_id = self._get_latest_tweet_id(tweets, new_since_id)