This repository has been archived by the owner on Mar 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CommandSender.py
106 lines (86 loc) · 3.1 KB
/
CommandSender.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from pynput.keyboard import Key, Controller
import pyperclip
import time
class CommandSender:
available = True
controller = None
commandSentAt = {}
commandCooldown = 2
def __init__(self, commandCooldown: int):
self.controller = Controller()
self.commandCooldown = commandCooldown
def plist(self, origin: str):
"""Sends a p list command
Args:
origin (str): The origin of the command
Returns:
Command information which should be printed
"""
return self.type("/p list", origin)
def who(self, origin: str):
"""Sends a who command
Args:
origin (str): The origin of the command
Returns:
Command information which should be printed
"""
return self.type("/who", origin)
def leave(self, origin: str):
"""Sends a leave command
Args:
origin (str): The origin of the command
Returns:
Command information which should be printed
"""
return self.type("/l", origin)
def pwarp(self, origin: str):
"""Sends a p warp command
Args:
origin (str): The origin of the command
Returns:
Command information which should be printed
"""
return self.type("/p warp", origin)
def pleave(self, origin: str):
"""Leaves and warps the party after
Args:
origin (str): The origin of the command
Returns:
Command information which should be printed
"""
self.leave(origin)
time.sleep(0.5)
self.pwarp(origin)
return "Sent commands ({}): /l and /p warp".format(origin)
def type(self, line: str, origin: str):
"""Writes a line using the virtual keyboard
Args:
line (str): The line to write
origin (str): The origin of the command
Returns:
Command information which should be printed
"""
if line in self.commandSentAt:
if time.time() - self.commandSentAt[line] > self.commandCooldown:
if not self.available:
return "Command sender unavailable (command: {} from {})".format(line, origin)
else:
return "Command on cooldown (command: {} from {} has {}s left on cooldown)".format(line, origin, self.commandCooldown - (self.commandSentAt[line] - time.time()))
self.commandSentAt[line] = time.time()
pyperclip.copy(line)
self.controller.press(Key.enter)
time.sleep(0.05)
self.controller.release(Key.enter)
self.controller.release(Key.shift)
self.controller.press("t")
self.controller.release("t")
time.sleep(0.05)
self.controller.press(Key.ctrl)
self.controller.press("v")
time.sleep(0.05)
self.controller.release(Key.ctrl)
self.controller.release("v")
time.sleep(0.1)
self.controller.press(Key.enter)
self.controller.release(Key.enter)
return "Sent command ({}): {}".format(origin, line)