forked from donadigo/TMInterfaceClientPython
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcustom_command.py
More file actions
32 lines (25 loc) · 1.04 KB
/
custom_command.py
File metadata and controls
32 lines (25 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from tminterface.interface import TMInterface
from tminterface.client import Client, run_client
import sys
class MainClient(Client):
def __init__(self) -> None:
super(MainClient, self).__init__()
def on_registered(self, iface: TMInterface) -> None:
print(f'Registered to {iface.server_name}')
iface.register_custom_command('echo')
def on_custom_command(self, iface, time_from: int, time_to: int, command: str, args: list):
# Usage: echo [message] [severity]
# echo "Something like this"
# echo "An error message" error
if command == 'echo':
if len(args) > 0:
severity = 'log' if len(args) == 1 else args[1]
iface.log(args[0], severity)
else:
iface.log('echo takes at least one argument', 'error')
def main():
server_name = f'TMInterface{sys.argv[1]}' if len(sys.argv) > 1 else 'TMInterface0'
print(f'Connecting to {server_name}...')
run_client(MainClient(), server_name)
if __name__ == '__main__':
main()