Obs:Migrate. Made Comm system more generic, including the ability to connect arbitrary protocols to channels. Re-worked the IRC connectivity system - you can now again communicate between IRC and in-game evennia channels.
This commit is contained in:
parent
c81d238b0c
commit
52785e8f3e
20 changed files with 960 additions and 258 deletions
|
|
@ -87,6 +87,7 @@ class DefaultCmdSet(CmdSet):
|
|||
self.add(comms.CmdChannelCreate())
|
||||
self.add(comms.CmdCdesc())
|
||||
self.add(comms.CmdPage())
|
||||
self.add(comms.CmdIRC2Chan())
|
||||
|
||||
# Batchprocessor commands
|
||||
self.add(batchprocess.CmdBatchCommands())
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
"""
|
||||
Comsys command module.
|
||||
"""
|
||||
|
||||
from src.comms.models import Channel, Msg, ChannelConnection
|
||||
from django.conf import settings
|
||||
from src.comms.models import Channel, Msg, PlayerChannelConnection, ExternalChannelConnection
|
||||
from src.comms import irc
|
||||
from src.comms.channelhandler import CHANNELHANDLER
|
||||
from src.utils import create, utils
|
||||
from src.commands.default.muxcommand import MuxCommand
|
||||
from src.server.sessionhandler import SESSIONS
|
||||
|
||||
def find_channel(caller, channelname, silent=False):
|
||||
"""
|
||||
|
|
@ -263,7 +265,7 @@ class CmdChannels(MuxCommand):
|
|||
caller.msg("No channels available")
|
||||
return
|
||||
# all channel we are already subscribed to
|
||||
subs = [conn.channel for conn in ChannelConnection.objects.get_all_player_connections(caller.player)]
|
||||
subs = [conn.channel for conn in PlayerChannelConnection.objects.get_all_player_connections(caller.player)]
|
||||
|
||||
if self.cmdstring != "comlist":
|
||||
|
||||
|
|
@ -823,3 +825,88 @@ class CmdPage(MuxCommand):
|
|||
if rstrings:
|
||||
caller.msg(rstrings = "\n".join(rstrings))
|
||||
caller.msg("You paged %s with: '%s'." % (", ".join(received), message))
|
||||
|
||||
|
||||
class CmdIRC2Chan(MuxCommand):
|
||||
"""
|
||||
@irc2chan - link evennia channel to an IRC channel
|
||||
|
||||
Usage:
|
||||
@irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>
|
||||
|
||||
Switches:
|
||||
/disconnect - this will delete the bot and remove the irc connection to the channel.
|
||||
/remove - "
|
||||
/list - show all irc<->evennia mappings
|
||||
|
||||
Example:
|
||||
@irc2chan myircchan = irc.dalnet.net 6667 myevennia-channel evennia-bot
|
||||
|
||||
This creates an IRC bot that connects to a given IRC network and channel. It will
|
||||
relay everything said in the evennia channel to the IRC channel and vice versa. The
|
||||
bot will automatically connect at server start, so this comman need only be given once.
|
||||
The /disconnect switch will permanently delete the bot. To only temporarily deactivate it,
|
||||
use the @services command instead.
|
||||
"""
|
||||
|
||||
key = "@irc2chan"
|
||||
locks = "cmd:serversetting(IRC_ENABLED) and perm(Wizards)"
|
||||
help_category = "Comms"
|
||||
|
||||
def func(self):
|
||||
"Setup the irc-channel mapping"
|
||||
|
||||
if 'list' in self.switches:
|
||||
# show all connections
|
||||
connections = ExternalChannelConnection.objects.filter(db_external_key__startswith='irc_')
|
||||
if connections:
|
||||
cols = [["Evennia channel"], ["IRC channel"]]
|
||||
for conn in connections:
|
||||
cols[0].append(conn.channel.key)
|
||||
cols[1].append(" ".join(conn.external_config.split('|')))
|
||||
ftable = utils.format_table(cols)
|
||||
string = ""
|
||||
for ir, row in enumerate(ftable):
|
||||
if ir == 0:
|
||||
string += "{w%s{n" % "".join(row)
|
||||
else:
|
||||
string += "\n" + "".join(row)
|
||||
self.caller.msg(string)
|
||||
else:
|
||||
self.caller.msg("No connections found.")
|
||||
return
|
||||
|
||||
if not settings.IRC_ENABLED:
|
||||
string = """IRC is not enabled. You need to activate it in game/settings.py."""
|
||||
self.caller.msg(string)
|
||||
return
|
||||
if not self.args or not self.rhs:
|
||||
string = "Usage: @irc2chan[/switches] <evennia_channel> = <ircnetwork> <port> <#irchannel> <botname>"
|
||||
self.caller.msg(string)
|
||||
return
|
||||
channel = self.lhs
|
||||
self.rhs = self.rhs.replace('#', ' ') # to avoid Python comment issues
|
||||
try:
|
||||
irc_network, irc_port, irc_channel, irc_botname = [part.strip() for part in self.rhs.split(None, 3)]
|
||||
irc_channel = "#%s" % irc_channel
|
||||
except Exception:
|
||||
string = "IRC bot definition '%s' is not valid." % self.rhs
|
||||
self.caller.msg(string)
|
||||
return
|
||||
|
||||
if 'disconnect' in self.switches or 'remove' in self.switches or 'delete' in self.switches:
|
||||
ok = irc.delete_connection(irc_network, irc_port, irc_channel, irc_botname)
|
||||
if not ok:
|
||||
self.caller.msg("IRC connection/bot could not be removed, does it exist?")
|
||||
else:
|
||||
self.caller.msg("IRC connection destroyed.")
|
||||
return
|
||||
|
||||
channel = find_channel(self.caller, channel)
|
||||
if not channel:
|
||||
return
|
||||
ok = irc.create_connection(channel, irc_network, irc_port, irc_channel, irc_botname)
|
||||
if not ok:
|
||||
self.caller.msg("This IRC connection already exists.")
|
||||
return
|
||||
self.caller.msg("Connection created. Starting IRC bot.")
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ def format_help_entry(title, help_text, aliases=None,
|
|||
"""
|
||||
This visually formats the help entry.
|
||||
"""
|
||||
string = "-"*70 + "\n"
|
||||
string = "-"*78 + "\n"
|
||||
if title:
|
||||
string += "Help topic for {w%s{n" % (title.capitalize())
|
||||
if aliases:
|
||||
|
|
@ -30,7 +30,7 @@ def format_help_entry(title, help_text, aliases=None,
|
|||
string += "\nSuggested:\n"
|
||||
string += fill(", ".join(suggested))
|
||||
string.strip()
|
||||
string += "\n" + "-"*70
|
||||
string += "\n" + "-"*78
|
||||
return string
|
||||
|
||||
def format_help_list(hdict_cmds, hdict_db):
|
||||
|
|
|
|||
|
|
@ -323,15 +323,17 @@ class CmdService(MuxCommand):
|
|||
@service[/switch] <service>
|
||||
|
||||
Switches:
|
||||
list - shows all available services (default)
|
||||
start - activates a service
|
||||
stop - stops a service
|
||||
list - shows all available services
|
||||
|
||||
Service management system. Allows for the listing,
|
||||
starting, and stopping of services.
|
||||
starting, and stopping of services. If no switches
|
||||
are given, services will be listed.
|
||||
"""
|
||||
|
||||
key = "@service"
|
||||
aliases = ["@services"]
|
||||
locks = "cmd:perm(service) or perm(Immortals)"
|
||||
help_category = "System"
|
||||
|
||||
|
|
@ -341,11 +343,9 @@ class CmdService(MuxCommand):
|
|||
caller = self.caller
|
||||
switches = self.switches
|
||||
|
||||
if not switches or \
|
||||
switches[0] not in ["list","start","stop"]:
|
||||
if switches and switches[0] not in ["list","start","stop"]:
|
||||
caller.msg("Usage: @service/<start|stop|list> [service]")
|
||||
return
|
||||
switch = switches[0]
|
||||
return
|
||||
|
||||
# get all services
|
||||
sessions = caller.sessions
|
||||
|
|
@ -353,19 +353,20 @@ class CmdService(MuxCommand):
|
|||
return
|
||||
service_collection = SESSIONS.server.services
|
||||
|
||||
if switch == "list":
|
||||
if not switches or switches[0] == "list":
|
||||
# Just display the list of installed services and their
|
||||
# status, then exit.
|
||||
string = "-" * 40
|
||||
string += "\nService Listing"
|
||||
string = "-" * 78
|
||||
string += "\n{wServices{n (use @services/start|stop):"
|
||||
|
||||
for service in service_collection.services:
|
||||
if service.running:
|
||||
status = 'Running'
|
||||
string += '\n * {g%s{n (%s)' % (service.name, status)
|
||||
else:
|
||||
status = 'Inactive'
|
||||
string += '\n * %s (%s)' % (service.name, status)
|
||||
string += "\n" + "-" * 40
|
||||
string += '\n {R%s{n (%s)' % (service.name, status)
|
||||
string += "\n" + "-" * 78
|
||||
caller.msg(string)
|
||||
return
|
||||
|
||||
|
|
@ -375,35 +376,34 @@ class CmdService(MuxCommand):
|
|||
service = service_collection.getServiceNamed(self.args)
|
||||
except Exception:
|
||||
string = 'Invalid service name. This command is case-sensitive. '
|
||||
string += 'See @service/list.'
|
||||
string += 'See @service/list for valid services.'
|
||||
caller.msg(string)
|
||||
return
|
||||
|
||||
if switch == "stop":
|
||||
if switches[0] == "stop":
|
||||
# Stopping a service gracefully closes it and disconnects
|
||||
# any connections (if applicable).
|
||||
|
||||
if not service.running:
|
||||
caller.msg('That service is not currently running.')
|
||||
return
|
||||
# We don't want to kill the main Evennia TCPServer services
|
||||
# here. If wanting to kill a listening port, one needs to
|
||||
# do it through settings.py and a restart.
|
||||
return
|
||||
if service.name[:7] == 'Evennia':
|
||||
string = "You can not stop Evennia TCPServer services this way."
|
||||
string += "\nTo e.g. remove a listening port, change settings file and restart."
|
||||
string = "You seem to be shutting down a core Evennia* service. Note that"
|
||||
string += "Stopping some TCP port services will *not* disconnect users *already*"
|
||||
string += "connected on those ports, but *may* instead cause spurious errors for them. To "
|
||||
string += "safely and permanently remove ports, change settings file and restart the server."
|
||||
caller.msg(string)
|
||||
return
|
||||
#comsys.cemit_mudinfo("%s is *Stopping* the service '%s'." % (sname, service.name)) #TODO!
|
||||
|
||||
service.stopService()
|
||||
caller.msg("Stopping service '%s'." % self.args)
|
||||
return
|
||||
|
||||
if switch == "start":
|
||||
if switches[0] == "start":
|
||||
#Starts a service.
|
||||
if service.running:
|
||||
caller.msg('That service is already running.')
|
||||
return
|
||||
#comsys.cemit_mudinfo("%s is *Starting* the service '%s'." % (sname,service.name)) #TODO!
|
||||
return
|
||||
caller.msg("Starting service '%s'." % self.args)
|
||||
service.startService()
|
||||
|
||||
class CmdShutdown(MuxCommand):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue