mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Bots use inputfunc
This commit is contained in:
parent
55d956a799
commit
e62418fd11
4 changed files with 40 additions and 29 deletions
|
|
@ -79,29 +79,6 @@ class BotStarter(DefaultScript):
|
|||
"""
|
||||
self.db.started = False
|
||||
|
||||
|
||||
class CmdBotListen(Command):
|
||||
"""
|
||||
This is a command that absorbs input aimed specifically at the
|
||||
bot. The session must prepend its data with bot_data_in for this
|
||||
to trigger.
|
||||
|
||||
"""
|
||||
key = "bot_data_in"
|
||||
def func(self):
|
||||
"Relay to typeclass"
|
||||
self.obj.execute_cmd(self.args.strip(), session=self.session)
|
||||
|
||||
class BotCmdSet(CmdSet):
|
||||
"""
|
||||
Holds the BotListen command
|
||||
|
||||
"""
|
||||
key = "botcmdset"
|
||||
def at_cmdset_creation(self):
|
||||
self.add(CmdBotListen())
|
||||
|
||||
|
||||
# Bot base class
|
||||
|
||||
class Bot(DefaultPlayer):
|
||||
|
|
@ -123,7 +100,6 @@ class Bot(DefaultPlayer):
|
|||
lockstring = "examine:perm(Wizards);edit:perm(Wizards);delete:perm(Wizards);boot:perm(Wizards);msg:false()"
|
||||
self.locks.add(lockstring)
|
||||
# set the basics of being a bot
|
||||
self.cmdset.add_default(BotCmdSet)
|
||||
script_key = "%s" % self.key
|
||||
self.scripts.add(BotStarter, key=script_key)
|
||||
self.is_bot = True
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue