Added cmd check to ABOT, commented out advancedcmd
advancedcmd doens't work atm, apparently function.func_code is a thing but adding co_consts isn't an attribute of that. Tested abot, seems to work well.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,8 +1,9 @@
|
||||
*.pyc
|
||||
*.class
|
||||
*sublime*
|
||||
|
||||
*.bat*
|
||||
secrets.py
|
||||
excluded.txt
|
||||
|
||||
# these are player/ingame specific
|
||||
files/
|
||||
|
||||
16
abot.py
16
abot.py
@@ -45,10 +45,8 @@ def on_abot_command(sender, command, label, args):
|
||||
return True
|
||||
|
||||
|
||||
@hook.event("player.AsyncPlayerChatEvent", "low")
|
||||
def on_chat(event):
|
||||
def check_msg(event, message):
|
||||
sender = event.getPlayer()
|
||||
message = event.getMessage().lower()
|
||||
for answer in answers:
|
||||
for regex in answer["regex"]:
|
||||
if regex.search(message):
|
||||
@@ -60,4 +58,16 @@ def on_chat(event):
|
||||
break
|
||||
|
||||
|
||||
@hook.event("player.AsyncPlayerChatEvent", "low")
|
||||
def on_chat(event):
|
||||
check_msg(event, event.getMessage().lower())
|
||||
|
||||
@hook.event("player.PlayerCommandPreprocessEvent", "low")
|
||||
def on_any_cmd(event):
|
||||
words = event.getMessage().lower().split(" ")
|
||||
cmd = words[0][1:]
|
||||
if cmd in ["msg", "m", "t", "pm", "mail", "r", "reply"]:
|
||||
info(" ".join(words[1:]))
|
||||
check_msg(event, " ".join(words[1:]))
|
||||
|
||||
load_answers()
|
||||
@@ -1,4 +1,5 @@
|
||||
from helpers import *
|
||||
import inspect, new
|
||||
|
||||
to_see_permission = "utils.showpermission" # See cmd permission in help
|
||||
|
||||
@@ -15,6 +16,8 @@ def simplecommand(cmd,
|
||||
permission = "utils." + cmd
|
||||
if not description:
|
||||
description = "Handles " + cmd
|
||||
if not usage:
|
||||
usage = "/%s <subcmd>" % cmd
|
||||
|
||||
def getHelp(sender):
|
||||
return helpMsg(sender, cmd, description, usage, aliases, permission)
|
||||
@@ -45,12 +48,11 @@ def simplecommand(cmd,
|
||||
return decorator
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
"""
|
||||
def advancedcommand(cmd,
|
||||
aliases = [],
|
||||
description = None,
|
||||
usage = None,
|
||||
senderLimit = -1,
|
||||
subCommands = []):
|
||||
cmd = cmd.lower()
|
||||
@@ -102,9 +104,7 @@ def advancedcommand(cmd,
|
||||
return called.call(sender, command, label, args)
|
||||
|
||||
def decorator(function):
|
||||
|
||||
functions = [func for func in function.__dict__.itervalues() if inspect.isfunction(func)]
|
||||
|
||||
functions = [new.function(c, globals()) for c in function.func_code.co_consts if inspect.iscode(c)]
|
||||
for sub in subCommands:
|
||||
sub.setParent(cmd)
|
||||
for func in functions:
|
||||
@@ -118,7 +118,13 @@ def advancedcommand(cmd,
|
||||
|
||||
class subcommand():
|
||||
|
||||
def __init__(self, cmd, aliases = [], amin = 0, amax = -1, description = None, usage = "[args...]", senderLimit = -1):
|
||||
def __init__(self, cmd,
|
||||
aliases = [],
|
||||
amin = 0,
|
||||
amax = -1,
|
||||
description = None,
|
||||
usage = "[args...]",
|
||||
senderLimit = -1):
|
||||
cmd = cmd.lower()
|
||||
self.description = description
|
||||
self.cmd = cmd
|
||||
@@ -132,24 +138,24 @@ class subcommand():
|
||||
def getHelp(sender):
|
||||
return helpMsg(sender, "%s %s" % (parent, cmd), description, usage, aliases, permission)
|
||||
|
||||
def setParent(parent):
|
||||
def setParent(self, parent):
|
||||
self.parent = parent
|
||||
self.permission = "utils.%s.%s" % (parent, cmd)
|
||||
self.description = description if description else "Handles /" + parent
|
||||
self.permission = "utils.%s.%s" % (parent, self.cmd)
|
||||
self.description = self.description if self.description else "Handles /" + parent
|
||||
|
||||
def setCalledFunction(function):
|
||||
def setCalledFunction(self, function):
|
||||
self.call = function
|
||||
|
||||
def isCalled(subcmd):
|
||||
alias = cmd
|
||||
def isCalled(self, subcmd):
|
||||
alias = self.cmd
|
||||
i = 0
|
||||
while (i <= len(aliases)):
|
||||
while (i <= len(self.aliases)):
|
||||
if alias == subcmd:
|
||||
return True
|
||||
alias = aliases[i]
|
||||
alias = self.aliases[i]
|
||||
i += 1
|
||||
return False
|
||||
|
||||
"""
|
||||
|
||||
def isSenderValid(senderLimit, isPlayer):
|
||||
return True if senderLimit == -1 else senderLimit != isPlayer
|
||||
|
||||
18
misc.py
18
misc.py
@@ -8,6 +8,24 @@ import org.bukkit.Bukkit as Bukkit
|
||||
import org.bukkit.event.player.PlayerChatEvent as PlayerChatEvent
|
||||
from basecommands import simplecommand
|
||||
|
||||
"""
|
||||
@advancedcommand("hi", aliases = ["hu"], description = "Says hi!", subCommands = [
|
||||
subcommand("server", aliases = ["serv"], amin = 1, amax = 4, usage = "[msg..]", senderLimit = 0),
|
||||
subcommand("me", aliases = ["meu"], amin = 2, amax = 5, usage = "[MESSAGE]")
|
||||
])
|
||||
def on_hi_command():
|
||||
|
||||
def server(sender, command, label, args):
|
||||
server.dispatchCommand(server.getConsoleSender(), "say " + " ".join(args[1:]))
|
||||
return "Success!"
|
||||
def me(sender, command, label, args):
|
||||
target = server.getPlayer(args[1])
|
||||
if target:
|
||||
target.chat(" ".join(args[2:]))
|
||||
return None
|
||||
return "No target found"
|
||||
"""
|
||||
|
||||
|
||||
@hook.event("player.PlayerJoinEvent", "monitor")
|
||||
def on_join(event):
|
||||
|
||||
Reference in New Issue
Block a user