Package: pvlv-commando
Pavlov CommandoCommands framework to handle text commands in a easy way.####Examplefrompvlv_commando.pvlv_commandoimportCommandofrompvlv_commandoimport(CommandNotFound,CommandExecutionFail,ArgVoidNotAllowed,ParamNotFound,MaxHourlyUses,MaxDailyUses,)defcommand_handler():com=Commando()# An example of incoming text from the chattext='.command this is a nice argument -d a text parameter -f -g'"""permission level of the user in the chat,it will be compared with the permissions needed to run the command,specified in the declaration file"""permissions=10iftext.startswith('.'):try:# text without the command invocation word, and the language of the commandcom.find_command(text[1:],'eng',permissions)"""Optional!You can specify in the command declaration file a max time use of the commandcause of computational weight of the command.Build a db where you save the number of executions by the user"""com.hourly_executions=12com.daily_executions=39"""to run the command you have to pass the bot object,that will be used inside commands.max_chunk_len: specify the max len of the out, some chats have a limit in length"""out=com.run_command(None,max_chunk_len=1500)ifout:"""Send to the chat with parse mode enabled** mean bold- if your chat dont support parse mode use com.run_manual().replace('**', '')- if your chat have a different parse mode use com.run_manual().replace('**', 'your_format')"""print(out)# DO NOT EXPOSE FULL EXCEPTIONS IN CHAT, ONLY THIS ARE READY FOR CHATexceptCommandNotFoundasexc:print(exc)exceptArgVoidNotAllowedasexc:print(exc)exceptParamNotFoundasexc:print(exc)exceptMaxHourlyUsesasexc:print(exc)exceptMaxDailyUsesasexc:print(exc)exceptCommandExecutionFailasexc:print(exc)# the exception to send in chat# the full report of the exception to send to a log chat or for internal log.print(exc.error_report)##Configurations file of the package:
Must be put in a folder "configs" in the root of the projectconfigs/commando.cfg[commands]
COMMANDS_DIR = commands/

[debug]
DEBUG = TrueAuto Command creationWith this tool you can automatically create a new command, with the default folders and filesfrompvlv_commandoimportStartCommanddefmain():# define the module name and the command name (use underscores only)nc=StartCommand('new_module','new_command')nc.create()"""The full command_declaration json file will be createdCheck the command_declaration json file to learn how to set up it"""if__name__=='__main__':main()###Command Declaration File
It's a json file called with the same name as the command.py file and the command folder.Everything with "OPTIONAL" label in the side comment can be omittedExample:{
    "management_command": 0,  # OPTIONAL, the commad is owner only
    "beta_command": false,  # OPTIONAL, the command in still in development
    "pro_command": 0,  # OPTIONAL, the command can be run only by pro users (pro level il arbitrary int)
    "dm_enabled": true,  # OPTIONAL, enabled in direct char, 1 to 1 with the bot
    "enabled_by_default": true,  # OPTIONAL, the command must be activare manually by the user
    "permissions": 0,  # OPTIONAL, the permission level to run the command
    "cost": 20,  # OPTIONAL, cost of the command, user might a value to run this command
    "hourly_max_uses": 10,  # OPTIONAL, man uses per hour by user
    "daily_max_uses": 90,  # OPTIONAL, man uses per day by user
    "invocation_words": ["command", "com"],  # the command invocation words
    "description": {
        "eng": "Short description of the command",
        "ita": "Breve descrizione del comando"
    },
    "handled_args": {  # must always contain at least one element, "" rappresent the void one
        "": {
            "eng": "Description of command without args",
            "ita": "Descrizione del comando senza argomenti"
        },
        "arg": {
            "eng": "Description of executions with this argument",
            "ita": "Descrizione dell' esecuzione con questo argomento"
        }
    },
    "handled_params": {  # OPTIONAL, the parameters
        "-param1": {
            "eng": "Description of executions with this parameter",
            "ita": "Descrizione dell'esecizione con questo parametro"
        },
        "-param2": {
            "eng": "Description of executions with this parameter",
            "ita": "Descrizione dell'esecizione con questo parametro"
        }
    }
}Command Class ExampleThis is the command file that will be run when the command is invokedclassCommandName(object):def__init__(self,bot,language,command,arg,params):self.bot=bot# bot entity to send messages, the one that you pass on run commandself.language=language# the language detected in the guild, to personalize responsesself.command=command# the command descriptor of the commandself.arg=arg# the detected arg"""parameters will be initialized hereYou have to reserve the vars here that you need to usein _vars must be the same name as handled_params in the config json but without dash (-)"""self._param1=None# the detected parametersself._param2=Noneforparaminparams:# read the parameter from the params dict and save them in vars over herename='_{}'.format(param[0])setattr(self,name,param[1])defrun(self):print('Command has been run arg:{}'.format(self.arg))