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
|
*.pyc
|
||||||
*.class
|
*.class
|
||||||
*sublime*
|
*sublime*
|
||||||
|
*.bat*
|
||||||
secrets.py
|
secrets.py
|
||||||
|
excluded.txt
|
||||||
|
|
||||||
# these are player/ingame specific
|
# these are player/ingame specific
|
||||||
files/
|
files/
|
||||||
|
|||||||
16
abot.py
16
abot.py
@@ -45,10 +45,8 @@ def on_abot_command(sender, command, label, args):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@hook.event("player.AsyncPlayerChatEvent", "low")
|
def check_msg(event, message):
|
||||||
def on_chat(event):
|
|
||||||
sender = event.getPlayer()
|
sender = event.getPlayer()
|
||||||
message = event.getMessage().lower()
|
|
||||||
for answer in answers:
|
for answer in answers:
|
||||||
for regex in answer["regex"]:
|
for regex in answer["regex"]:
|
||||||
if regex.search(message):
|
if regex.search(message):
|
||||||
@@ -60,4 +58,16 @@ def on_chat(event):
|
|||||||
break
|
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()
|
load_answers()
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
from helpers import *
|
from helpers import *
|
||||||
|
import inspect, new
|
||||||
|
|
||||||
to_see_permission = "utils.showpermission" # See cmd permission in help
|
to_see_permission = "utils.showpermission" # See cmd permission in help
|
||||||
|
|
||||||
@@ -15,6 +16,8 @@ def simplecommand(cmd,
|
|||||||
permission = "utils." + cmd
|
permission = "utils." + cmd
|
||||||
if not description:
|
if not description:
|
||||||
description = "Handles " + cmd
|
description = "Handles " + cmd
|
||||||
|
if not usage:
|
||||||
|
usage = "/%s <subcmd>" % cmd
|
||||||
|
|
||||||
def getHelp(sender):
|
def getHelp(sender):
|
||||||
return helpMsg(sender, cmd, description, usage, aliases, permission)
|
return helpMsg(sender, cmd, description, usage, aliases, permission)
|
||||||
@@ -45,12 +48,11 @@ def simplecommand(cmd,
|
|||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
def advancedcommand(cmd,
|
def advancedcommand(cmd,
|
||||||
aliases = [],
|
aliases = [],
|
||||||
description = None,
|
description = None,
|
||||||
|
usage = None,
|
||||||
senderLimit = -1,
|
senderLimit = -1,
|
||||||
subCommands = []):
|
subCommands = []):
|
||||||
cmd = cmd.lower()
|
cmd = cmd.lower()
|
||||||
@@ -102,9 +104,7 @@ def advancedcommand(cmd,
|
|||||||
return called.call(sender, command, label, args)
|
return called.call(sender, command, label, args)
|
||||||
|
|
||||||
def decorator(function):
|
def decorator(function):
|
||||||
|
functions = [new.function(c, globals()) for c in function.func_code.co_consts if inspect.iscode(c)]
|
||||||
functions = [func for func in function.__dict__.itervalues() if inspect.isfunction(func)]
|
|
||||||
|
|
||||||
for sub in subCommands:
|
for sub in subCommands:
|
||||||
sub.setParent(cmd)
|
sub.setParent(cmd)
|
||||||
for func in functions:
|
for func in functions:
|
||||||
@@ -118,7 +118,13 @@ def advancedcommand(cmd,
|
|||||||
|
|
||||||
class subcommand():
|
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()
|
cmd = cmd.lower()
|
||||||
self.description = description
|
self.description = description
|
||||||
self.cmd = cmd
|
self.cmd = cmd
|
||||||
@@ -132,24 +138,24 @@ class subcommand():
|
|||||||
def getHelp(sender):
|
def getHelp(sender):
|
||||||
return helpMsg(sender, "%s %s" % (parent, cmd), description, usage, aliases, permission)
|
return helpMsg(sender, "%s %s" % (parent, cmd), description, usage, aliases, permission)
|
||||||
|
|
||||||
def setParent(parent):
|
def setParent(self, parent):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.permission = "utils.%s.%s" % (parent, cmd)
|
self.permission = "utils.%s.%s" % (parent, self.cmd)
|
||||||
self.description = description if description else "Handles /" + parent
|
self.description = self.description if self.description else "Handles /" + parent
|
||||||
|
|
||||||
def setCalledFunction(function):
|
def setCalledFunction(self, function):
|
||||||
self.call = function
|
self.call = function
|
||||||
|
|
||||||
def isCalled(subcmd):
|
def isCalled(self, subcmd):
|
||||||
alias = cmd
|
alias = self.cmd
|
||||||
i = 0
|
i = 0
|
||||||
while (i <= len(aliases)):
|
while (i <= len(self.aliases)):
|
||||||
if alias == subcmd:
|
if alias == subcmd:
|
||||||
return True
|
return True
|
||||||
alias = aliases[i]
|
alias = self.aliases[i]
|
||||||
i += 1
|
i += 1
|
||||||
return False
|
return False
|
||||||
|
"""
|
||||||
|
|
||||||
def isSenderValid(senderLimit, isPlayer):
|
def isSenderValid(senderLimit, isPlayer):
|
||||||
return True if senderLimit == -1 else 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
|
import org.bukkit.event.player.PlayerChatEvent as PlayerChatEvent
|
||||||
from basecommands import simplecommand
|
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")
|
@hook.event("player.PlayerJoinEvent", "monitor")
|
||||||
def on_join(event):
|
def on_join(event):
|
||||||
|
|||||||
Reference in New Issue
Block a user