Bots use inputfunc

This commit is contained in:
Tablet-PC\cloud 2017-01-18 12:26:42 +11:00
parent 55d956a799
commit e62418fd11
4 changed files with 40 additions and 29 deletions

View file

@ -80,6 +80,41 @@ def text(session, *args, **kwargs):
session.update_session_counters()
def bot_data_in(session, *args, **kwargs):
"""
Text input from the IRC and RSS bots.
This will trigger the execute_cmd method on the bots in-game counterpart.
Args:
text (str): First arg is text input. Other arguments are ignored.
"""
text = args[0] if args else None
# Explicitly check for None since text can be an empty string, which is
# also valid
if text is None:
return
# this is treated as a command input
# handle the 'idle' command
if text.strip() in _IDLE_COMMAND:
session.update_session_counters(idle=True)
return
if session.player:
# nick replacement
puppet = session.puppet
if puppet:
text = puppet.nicks.nickreplace(text,
categories=("inputline", "channel"), include_player=True)
else:
text = session.player.nicks.nickreplace(text,
categories=("inputline", "channel"), include_player=False)
kwargs.pop("options", None)
session.player.execute_cmd(text=text, session=session)
session.update_session_counters()
def echo(session, *args, **kwargs):
"""
Echo test function

View file

@ -178,7 +178,7 @@ class IRCBot(irc.IRCClient, Session):
if not msg.startswith('***'):
user = user.split('!', 1)[0]
user = ansi.raw(user)
self.data_in("bot_data_in %s@%s: %s" % (user, channel, msg))
self.data_in("%s@%s: %s" % (user, channel, msg))
def action(self, user, channel, msg):
"""
@ -192,7 +192,7 @@ class IRCBot(irc.IRCClient, Session):
"""
if not msg.startswith('**'):
user = user.split('!', 1)[0]
self.data_in("bot_data_in %s@%s %s" % (user, channel, msg))
self.data_in("%s@%s %s" % (user, channel, msg))
def data_in(self, text=None, **kwargs):
"""
@ -204,7 +204,7 @@ class IRCBot(irc.IRCClient, Session):
"""
self.sessionhandler.data_in(self, text=text, **kwargs)
self.sessionhandler.data_in(self, bot_data_in=text, **kwargs)
def send_text(self, *args, **kwargs):
"""

View file

@ -80,7 +80,7 @@ class RSSReader(Session):
if not init:
# for initialization we just ignore old entries
for entry in reversed(new_entries):
self.data_in("bot_data_in " + entry)
self.data_in(entry)
def data_in(self, text=None, **kwargs):
"""
@ -91,7 +91,7 @@ class RSSReader(Session):
kwargs (any): Options from protocol.
"""
self.sessionhandler.data_in(self, text=text, **kwargs)
self.sessionhandler.data_in(self, bot_data_in=text, **kwargs)
def _errback(self, fail):
"Report error"