2.0 KiB
2.0 KiB
XHandler
import PyserSSH.extensions.XHandler as XHandler
XHandler is eXternal Handler. Coding your command like discord.py
Setup
You can enable XHandler by
XH = XHandler()
ssh = Server(XHandler=XH)
This enable is disable command
event and enable 2 event. click here goto XHandler event.
Quick Example
@XH.command()
def calculate(client, mode="add", x=3, y=1, hello=False):
"""Perform mathematical operations."""
x, y, = int(x), int(y)
if mode == "add":
Send(client, x + y)
elif mode == "sub":
Send(client, x - y)
elif mode == "mul":
Send(client, x * y)
elif mode == "div":
Send(client, x / y)
if hello:
Send(client, "Hello World!")
> calculate
4
this command you can custom value by use -
in your command
> calculate -mode sub
2
> calculate -x 5 -y 2
7
> calculate -x 5 -y 2 -mode mul
10
you can use --
for boolean only
> calculate --hello
4
Hello World!
Help command
You can disable help command by enablehelp=False
> help
No Category:
calculate - Perform mathematical operations.
you can use help <command>
for more command info
> help calculate
calculate
Perform mathematical operations.
Usage: calculate [-mode add] [-x 3] [-y 1] [--hello]
Error
You can show error input command by showusageonworng=False
Command Not Found
> hello
hello not found
Handle
You can handle command not found by using .commandnotfound
def notfound(client, command):
# your process
XH.commandnotfound = notfound
Missing argument
if enable showusageonworng
> hello
hello
Usage: hello <testvalue>
or if disable showusageonworng
Missing required argument 'testvalue' for command 'hello'
Invalid argument
if enable showusageonworng
> hello -testvalue
hello
Usage: hello <testvalue>
or if disable showusageonworng
> hello -testvalue
Invalid number of arguments for command 'hello'.