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
|
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
|
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):
|
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.
|
- 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:
|
if not self.ndb.ev_channel and self.db.ev_channel:
|
||||||
# cache channel lookup
|
# cache channel lookup
|
||||||
self.ndb.ev_channel = self.db.ev_channel
|
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_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]:
|
if not from_obj or from_obj != [self.id]:
|
||||||
text = "bot_data_out %s" % text
|
super(IRCBot, self).msg(text=text, options={"bot_data_out": True})
|
||||||
super(IRCBot, self).msg(text=text)
|
|
||||||
|
|
||||||
def execute_cmd(self, text=None, session=None):
|
def execute_cmd(self, text=None, session=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -391,8 +391,7 @@ class IMC2Bot(Bot):
|
||||||
self.ndb.ev_channel = self.db.ev_channel
|
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_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]:
|
if "from_obj" not in options or options["from_obj"] != [self.id]:
|
||||||
text = "bot_data_out %s" % text
|
self.msg(text=text, options={"bot_data_out": True})
|
||||||
self.msg(text=text)
|
|
||||||
|
|
||||||
def execute_cmd(self, text=None, session=None):
|
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)
|
from_obj.at_msg_send(text=text, to_obj=self, **kwargs)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
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
|
# session relay
|
||||||
sessions = make_iter(session) if session else self.sessions.all()
|
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)
|
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:
|
Kwargs:
|
||||||
text (str): Outgoing text.
|
bot_data_out (bool): If True, echo to channel.
|
||||||
kwargs (any): Other data to protocol.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if text.startswith("bot_data_out"):
|
text = args[0] if args else ""
|
||||||
text = text.split(" ", 1)[1]
|
if text and kwargs['options'].get("bot_data_out", False):
|
||||||
text = parse_irc_colors(text)
|
text = parse_irc_colors(text)
|
||||||
self.say(self.channel, text)
|
self.say(self.channel, text)
|
||||||
|
|
||||||
|
def send_default(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Ignore other types of sends.
|
||||||
|
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class IRCBotFactory(protocol.ReconnectingClientFactory):
|
class IRCBotFactory(protocol.ReconnectingClientFactory):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ class SessionHandler(dict):
|
||||||
applied.
|
applied.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
options = kwargs.get("options", None) or {}
|
options = kwargs.pop("options", None) or {}
|
||||||
raw = options.get("raw", False)
|
raw = options.get("raw", False)
|
||||||
strip_inlinefunc = options.get("strip_inlinefunc", False)
|
strip_inlinefunc = options.get("strip_inlinefunc", False)
|
||||||
|
|
||||||
|
|
@ -204,6 +204,7 @@ class SessionHandler(dict):
|
||||||
rkwargs[key] = [ _validate(data), {} ]
|
rkwargs[key] = [ _validate(data), {} ]
|
||||||
else:
|
else:
|
||||||
rkwargs[key] = [ [_validate(data)], {} ]
|
rkwargs[key] = [ [_validate(data)], {} ]
|
||||||
|
rkwargs[key][1]["options"] = options
|
||||||
|
|
||||||
return rkwargs
|
return rkwargs
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue