Made IRC work with new send mechanism, as per #924.
This commit is contained in:
parent
6782ff1333
commit
ddb87d6aea
4 changed files with 32 additions and 15 deletions
|
|
@ -135,12 +135,12 @@ class Bot(DefaultPlayer):
|
|||
"""
|
||||
pass
|
||||
|
||||
def msg(self, text=None, from_obj=None, session=None, **kwargs):
|
||||
def msg(self, text=None, from_obj=None, session=None, options=None, **kwargs):
|
||||
"""
|
||||
Evennia -> outgoing protocol
|
||||
|
||||
"""
|
||||
super(Bot, self).msg(text=text, from_obj=from_obj, session=session, **kwargs)
|
||||
super(Bot, self).msg(text=text, from_obj=from_obj, session=session, options=options, **kwargs)
|
||||
|
||||
def execute_cmd(self, raw_string, session=None):
|
||||
"""
|
||||
|
|
@ -233,14 +233,14 @@ class IRCBot(Bot):
|
|||
- from_obj (str): dbid of an object sending this text.
|
||||
|
||||
"""
|
||||
options = kwargs.get("options", {})
|
||||
from_obj = kwargs.get("from_obj", None)
|
||||
options = kwargs.get("options", None) or {}
|
||||
if not self.ndb.ev_channel and self.db.ev_channel:
|
||||
# cache channel lookup
|
||||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if "from_channel" in options and text and self.ndb.ev_channel.dbid == options["from_channel"]:
|
||||
if "from_obj" not in options or options["from_obj"] != [self.id]:
|
||||
text = "bot_data_out %s" % text
|
||||
super(IRCBot, self).msg(text=text)
|
||||
if not from_obj or from_obj != [self.id]:
|
||||
super(IRCBot, self).msg(text=text, options={"bot_data_out": True})
|
||||
|
||||
def execute_cmd(self, text=None, session=None):
|
||||
"""
|
||||
|
|
@ -391,8 +391,7 @@ class IMC2Bot(Bot):
|
|||
self.ndb.ev_channel = self.db.ev_channel
|
||||
if "from_channel" in options and text and self.ndb.ev_channel.dbid == options["from_channel"]:
|
||||
if "from_obj" not in options or options["from_obj"] != [self.id]:
|
||||
text = "bot_data_out %s" % text
|
||||
self.msg(text=text)
|
||||
self.msg(text=text, options={"bot_data_out": True})
|
||||
|
||||
def execute_cmd(self, text=None, session=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -409,6 +409,14 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
|
|||
from_obj.at_msg_send(text=text, to_obj=self, **kwargs)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
if not self.at_msg_receive(text=text, **kwargs):
|
||||
# abort message to this player
|
||||
return
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
kwargs["options"] = options
|
||||
|
||||
# session relay
|
||||
sessions = make_iter(session) if session else self.sessions.all()
|
||||
|
|
|
|||
|
|
@ -204,20 +204,29 @@ class IRCBot(irc.IRCClient, Session):
|
|||
"""
|
||||
self.sessionhandler.data_in(self, text=text, **kwargs)
|
||||
|
||||
def data_out(self, text=None, **kwargs):
|
||||
def send_text(self, *args, **kwargs):
|
||||
"""
|
||||
Data from server-> IRC.
|
||||
Send channel text to IRC
|
||||
|
||||
Args:
|
||||
text (str): Outgoing text
|
||||
|
||||
Kwargs:
|
||||
text (str): Outgoing text.
|
||||
kwargs (any): Other data to protocol.
|
||||
bot_data_out (bool): If True, echo to channel.
|
||||
|
||||
"""
|
||||
if text.startswith("bot_data_out"):
|
||||
text = text.split(" ", 1)[1]
|
||||
text = args[0] if args else ""
|
||||
if text and kwargs['options'].get("bot_data_out", False):
|
||||
text = parse_irc_colors(text)
|
||||
self.say(self.channel, text)
|
||||
|
||||
def send_default(self, *args, **kwargs):
|
||||
"""
|
||||
Ignore other types of sends.
|
||||
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class IRCBotFactory(protocol.ReconnectingClientFactory):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ class SessionHandler(dict):
|
|||
applied.
|
||||
|
||||
"""
|
||||
options = kwargs.get("options", None) or {}
|
||||
options = kwargs.pop("options", None) or {}
|
||||
raw = options.get("raw", False)
|
||||
strip_inlinefunc = options.get("strip_inlinefunc", False)
|
||||
|
||||
|
|
@ -204,6 +204,7 @@ class SessionHandler(dict):
|
|||
rkwargs[key] = [ _validate(data), {} ]
|
||||
else:
|
||||
rkwargs[key] = [ [_validate(data)], {} ]
|
||||
rkwargs[key][1]["options"] = options
|
||||
|
||||
return rkwargs
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue