-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcon.py
48 lines (34 loc) · 1002 Bytes
/
rcon.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from rcon.shell import Rcon
from rcon.completer import SimpleCompleter
from rcon import history_path
try:
import gnureadline as readline
except ImportError:
import readline
import asyncio
import logging
import typer
app = typer.Typer()
# TODO: load config from file or input
# HOST = "192.168.0.30"
# PORT = 25575
# PASSWORD = "logitech"
LOG_FILENAME = "/tmp/completer.log"
logging.basicConfig(
format="%(message)s",
filename=LOG_FILENAME,
level=logging.DEBUG,
)
# 注册补全功能
with open(history_path, "r") as f:
OPTIONS = [line.replace("\n", "") for line in f.readlines()]
readline.set_completer(SimpleCompleter(OPTIONS).complete)
# 使用 Tab 键补全
readline.parse_and_bind("tab: complete")
# 使用 vi 模式
readline.parse_and_bind("set editing-mode vi")
def main(host: str, port: int, password: str):
connection = Rcon(host=host, port=port, password=password)
asyncio.run(connection.mainloop())
if __name__ == "__main__":
typer.run(main)