Browse Source

Updated docs and added a failsafe return in PyIRCBot.messageHasCommand

dave/xdcc
dave 8 years ago
parent
commit
63463f40f2
  1. 18
      pyircbot/core/pyircbot.py

18
pyircbot/core/pyircbot.py

@ -513,23 +513,25 @@ class PyIRCBot(asynchat.async_chat):
@staticmethod
def messageHasCommand(command, message, requireArgs=False):
"""Check if a message has a command with or without args in it
:param command: the command string to look for, like !ban. If a list is passed, the first match is returned.
:type command: str or list
:param message: the message string to look in, like "!ban Lil_Mac"
:type message: str
:param requireArgs: if true, only validate if the command use has any amount of trailing text
:type requireArgs: bool"""
if not type(command)==list:
command = [command]
for item in command:
cmd = PyIRCBot.messageHasCommandSingle(item, message, requireArgs)
if cmd:
return cmd
return False
@staticmethod
def messageHasCommandSingle(command, message, requireArgs=False):
"""Check if a message has a command with or without args in it
:param command: the command string to look for, like !ban
:type command: str
:param message: the message string to look in, like "!ban Lil_Mac"
:type message: str
:param requireArgs: if true, only validate if the command use has any amount of trailing text
:type requireArgs: bool"""
# Check if the message at least starts with the command
messageBeginning = message[0:len(command)]
if messageBeginning!=command:

Loading…
Cancel
Save