Change new irc2chan command syntax to use :typeclass, which is more in line with how typeclass is provided in other commands using typeclass. Also add exception handling if trying to create the bot with a malformed typeclass.
This commit is contained in:
parent
9503b30a5e
commit
1d181d8259
1 changed files with 23 additions and 12 deletions
|
|
@ -801,7 +801,7 @@ class CmdIRC2Chan(COMMAND_DEFAULT_CLASS):
|
||||||
link an evennia channel to an external IRC channel
|
link an evennia channel to an external IRC channel
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
@irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname> [botpath]
|
@irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>[:typeclass]
|
||||||
@irc2chan/delete botname|#dbid
|
@irc2chan/delete botname|#dbid
|
||||||
|
|
||||||
Switches:
|
Switches:
|
||||||
|
|
@ -813,14 +813,18 @@ class CmdIRC2Chan(COMMAND_DEFAULT_CLASS):
|
||||||
/ssl - use an SSL-encrypted connection
|
/ssl - use an SSL-encrypted connection
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
@irc2chan myircchan = irc.dalnet.net 6667 myevennia-channel evennia-bot
|
@irc2chan myircchan = irc.dalnet.net 6667 #mychannel evennia-bot
|
||||||
|
@irc2chan public = irc.freenode.net 6667 #evgaming #evbot:players.mybot.MyBot
|
||||||
|
|
||||||
This creates an IRC bot that connects to a given IRC network and channel.
|
This creates an IRC bot that connects to a given IRC network and
|
||||||
It will relay everything said in the evennia channel to the IRC channel and
|
channel. If a custom typeclass path is given, this will be used
|
||||||
vice versa. The bot will automatically connect at server start, so this
|
instead of the default bot class.
|
||||||
command need only be given once. The /disconnect switch will permanently
|
The bot will relay everything said in the evennia channel to the
|
||||||
delete the bot. To only temporarily deactivate it, use the {w@services{n
|
IRC channel and vice versa. The bot will automatically connect at
|
||||||
command instead. Provide an optional bot class path to use a custom bot.
|
server start, so this command need only be given once. The
|
||||||
|
/disconnect switch will permanently delete the bot. To only
|
||||||
|
temporarily deactivate it, use the |w@services|n command instead.
|
||||||
|
Provide an optional bot class path to use a custom bot.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
key = "@irc2chan"
|
key = "@irc2chan"
|
||||||
|
|
@ -866,7 +870,7 @@ class CmdIRC2Chan(COMMAND_DEFAULT_CLASS):
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.args or not self.rhs:
|
if not self.args or not self.rhs:
|
||||||
string = "Usage: @irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>"
|
string = "Usage: @irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>[:typeclass]"
|
||||||
self.msg(string)
|
self.msg(string)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
@ -874,16 +878,19 @@ class CmdIRC2Chan(COMMAND_DEFAULT_CLASS):
|
||||||
self.rhs = self.rhs.replace('#', ' ') # to avoid Python comment issues
|
self.rhs = self.rhs.replace('#', ' ') # to avoid Python comment issues
|
||||||
try:
|
try:
|
||||||
irc_network, irc_port, irc_channel, irc_botname = \
|
irc_network, irc_port, irc_channel, irc_botname = \
|
||||||
[part.strip() for part in self.rhs.split()[:4]]
|
[part.strip() for part in self.rhs.split(None, 4)]
|
||||||
irc_channel = "#%s" % irc_channel
|
irc_channel = "#%s" % irc_channel
|
||||||
except Exception:
|
except Exception:
|
||||||
string = "IRC bot definition '%s' is not valid." % self.rhs
|
string = "IRC bot definition '%s' is not valid." % self.rhs
|
||||||
self.msg(string)
|
self.msg(string)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
botclass = None
|
||||||
|
if ":" in irc_botname:
|
||||||
|
irc_botname, botclass = [part.strip() for part in irc_botname.split(":", 2)]
|
||||||
botname = "ircbot-%s" % irc_botname
|
botname = "ircbot-%s" % irc_botname
|
||||||
# If path given, use custom bot otherwise use default.
|
# If path given, use custom bot otherwise use default.
|
||||||
botclass = self.rhs.split()[4] if len(self.rhs.split()) == 5 else bots.IRCBot
|
botclass = botclass if botclass else bots.IRCBot
|
||||||
irc_ssl = "ssl" in self.switches
|
irc_ssl = "ssl" in self.switches
|
||||||
|
|
||||||
# create a new bot
|
# create a new bot
|
||||||
|
|
@ -895,7 +902,11 @@ class CmdIRC2Chan(COMMAND_DEFAULT_CLASS):
|
||||||
self.msg("Player '%s' already exists and is not a bot." % botname)
|
self.msg("Player '%s' already exists and is not a bot." % botname)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
bot = create.create_player(botname, None, None, typeclass=botclass)
|
try:
|
||||||
|
bot = create.create_player(botname, None, None, typeclass=botclass)
|
||||||
|
except Exception as err:
|
||||||
|
self.msg("|rError, could not create the bot:|n '%s'." % err)
|
||||||
|
return
|
||||||
bot.start(ev_channel=channel, irc_botname=irc_botname, irc_channel=irc_channel,
|
bot.start(ev_channel=channel, irc_botname=irc_botname, irc_channel=irc_channel,
|
||||||
irc_network=irc_network, irc_port=irc_port, irc_ssl=irc_ssl)
|
irc_network=irc_network, irc_port=irc_port, irc_ssl=irc_ssl)
|
||||||
self.msg("Connection created. Starting IRC bot.")
|
self.msg("Connection created. Starting IRC bot.")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue