* Send replies only to the channel from which the request came

* Send general messages to all served channels
 * Prefix all replies with the nickname of the user who made the request


git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@7105 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2009-04-20 22:38:58 +00:00 committed by Git SVN Gateway
parent bbfe5e2abd
commit 6461dd0208
1 changed files with 22 additions and 19 deletions

View File

@ -65,27 +65,27 @@ class Bot:
self.check.stop() self.check.stop()
self.check.join() self.check.join()
def write(self, text): def write(self, text, channels = None):
return self.irc.write(text) return self.irc.write(text, channels)
class BotCommands: class BotCommands:
def ping(self): def ping(self, nick, channel):
self.bot.write("pong") self.bot.write("%s: pong" % (nick), [channel])
def help(self): def help(self, nick, channel):
self.bot.write("I'm a bot that shows information from the \x02Warzone 2100\x02 lobby server. I was created by %s. For information about commands you can try: \"commands\"" % (__author__)) self.bot.write("%s: I'm a bot that shows information from the \x02Warzone 2100\x02 lobby server. I was created by %s. For information about commands you can try: \"commands\"" % (nick, __author__), [channel])
def info(self): # Alias 'info' to 'help'
return self.help() info = help
def commands(self): def commands(self, nick, channel):
self.bot.write("ping: pong, help/info: general information about this bot, list: show which games are currenly being hosted") self.bot.write("%s: ping: pong, help/info: general information about this bot, list: show which games are currenly being hosted" % (nick), [channel])
def list(self): def list(self, nick, channel):
try: try:
games = self.bot.lobby.list(allowException = True) games = self.bot.lobby.list(allowException = True)
if not games: if not games:
self.bot.write("No games in lobby") self.bot.write("%s: No games in lobby" % (nick), [channel])
else: else:
if len(games) == 1: if len(games) == 1:
message = "1 game hosted: " message = "1 game hosted: "
@ -93,9 +93,9 @@ class BotCommands:
message = "%i games hosted: " % (len(games)) message = "%i games hosted: " % (len(games))
l = ["\x02%s\x02 [%i/%i]" % (g.description, g.currentPlayers, g.maxPlayers) for g in games] l = ["\x02%s\x02 [%i/%i]" % (g.description, g.currentPlayers, g.maxPlayers) for g in games]
message += ", ".join(l) message += ", ".join(l)
self.bot.write(message) self.bot.write("%s: %s" % (nick, message), [channel])
except socket.timeout: except socket.timeout:
self.bot.write("Failed to communicate with the lobby (%s:%d)" % (self.bot.lobby.host, self.bot.lobby.port)) self.bot.write("%s: Failed to communicate with the lobby (%s:%d)" % (nick, self.bot.lobby.host, self.bot.lobby.port), [channel])
# TODO: if message.startswith("show") # join a game and show information about it # TODO: if message.startswith("show") # join a game and show information about it
@ -162,8 +162,8 @@ class bot_connection:
"""Read a message from IRC and handle it.""" """Read a message from IRC and handle it."""
return self.connection.readAndHandle() return self.connection.readAndHandle()
def write(self, line): def write(self, line, channels = None):
self.connection.write(line) return self.connection.write(line, channels)
class irc_connection: class irc_connection:
def __init__(self, bot, server, port, serve_channels, silent_channels, nick, nickpass = None): def __init__(self, bot, server, port, serve_channels, silent_channels, nick, nickpass = None):
@ -207,13 +207,16 @@ class irc_connection:
self.privmsg(channel, '%s: Unknown command \'%s\'. Try \'commands\'.' % (nick, message)) self.privmsg(channel, '%s: Unknown command \'%s\'. Try \'commands\'.' % (nick, message))
if func: if func:
func() func(nick, channel)
else: else:
# Not the serviced channel, point the user at the correct channel # Not the serviced channel, point the user at the correct channel
self.notice(nick, 'Sorry %s, I will not provide my services in this channel. Please find me in one of %s' % (nick, ', '.join(self.serve_channels))) self.notice(nick, 'Sorry %s, I will not provide my services in this channel. Please find me in one of %s' % (nick, ', '.join(self.serve_channels)))
def write(self, line): def write(self, line, channels = None):
self.privmsg(self.channel, line) if not channels:
channels = self.serve_channels
for channel in channels:
self.privmsg(channel, line)
class line_socket: class line_socket: