Private message fixes, requireCommand config option.

This commit is contained in:
oddluck 2019-12-08 04:01:53 +00:00
parent 1d7b61a931
commit 98e2440ff2
3 changed files with 19 additions and 12 deletions

View File

@ -14,7 +14,7 @@ Looks for games in ./games/ directory
usage:
open <game name> ex. open zork1.z5 - loads game
adventure <game name> ex. adventure zork1.z5 - starts game
Game will process channel messages as commands while a game is running.

View File

@ -32,4 +32,8 @@ conf.registerGlobalValue(TextAdventures, 'dfrotzPath',
conf.registerGlobalValue(TextAdventures, 'allowPrivate',
registry.Boolean('True', _("""Allow games to be played over private message.""")))
conf.registerGlobalValue(TextAdventures, 'requireCommand',
registry.Boolean('False', _("""Require game input to be sent via command. Disables
monitoring of chanel messages for game input.""")))
TextAdventures = conf.registerPlugin('TextAdventures')

View File

@ -36,7 +36,7 @@ class TextAdventures(callbacks.Plugin):
self.game_path = "{0}/games/".format(os.path.dirname(os.path.abspath(__file__)))
self.binary = self.registryValue('dFrotzPath')
def open(self, irc, msg, args, input):
def adventure(self, irc, msg, args, input):
"""<game_name>
Open <game_name.z*>.
"""
@ -58,7 +58,7 @@ class TextAdventures(callbacks.Plugin):
for line in response:
if line.strip() and line.strip() != ".":
irc.reply(line, prefixNick=False)
open = wrap(open, ['text'])
adventure = wrap(adventure, ['text'])
def output(self, output):
response = []
@ -77,18 +77,21 @@ class TextAdventures(callbacks.Plugin):
def doPrivmsg(self, irc, msg):
channel = msg.args[0]
if callbacks.addressed(irc.nick, msg):
if irc.isChannel(channel) and callbacks.addressed(irc.nick, msg):
return
if not irc.isChannel(channel):
channel = msg.nick
self.game.setdefault(channel, None)
if self.game[channel]:
command = msg.args[1]
self.game[channel].sendline(r'{}'.format(command))
response = self.output(self.game[channel])
for line in response[1:]:
if line.strip() and line.strip() != ".":
irc.reply(line, prefixNick=False)
if not self.registryValue('requireCommand') or not irc.isChannel(msg.args[0]):
self.game.setdefault(channel, None)
if self.game[channel]:
command = msg.args[1]
self.game[channel].sendline(r'{}'.format(command))
response = self.output(self.game[channel])
for line in response[1:]:
if line.strip() and line.strip() != ".":
irc.reply(line, prefixNick=False)
else:
return
def end(self, irc, msg, args):
"""