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.
This commit is contained in:
parent
752515a628
commit
3e63c2e458
@ -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.
|
||||
|
||||
|
@ -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.'
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user