-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.py
107 lines (79 loc) · 2.95 KB
/
common.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
107
import os
import random
import json
import time
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = "1"
from pygame import mixer, time as pytime
import pygetwindow as gw
current_directory = os.getcwd()
with open(os.path.join(current_directory, "settings.json"), "r", encoding="utf-8") as file:
settings = json.load(file)
translations_path = os.path.join(current_directory, "translations.json")
numbers = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "10", "11", "12", "13", "14", "15","16", "17", "18", "19", "20"][::-1]
keys = ["q", "w", "e", "r", "t", "y", "u", "a", "s", "d", "f", "g", "h", "j","z", "x", "c", "v", "b", "n", "m"][::-1]
def speak(say, sfx):
if sfx:
path = os.path.join(current_directory, "sounds", say)
options = os.listdir(path)
choise = random.choice(options)
choise = os.path.join(path,choise)
mixer.init()
mixer.music.load(choise)
mixer.music.play()
while mixer.music.get_busy():
pytime.Clock().tick(10)
mixer.quit()
def load_translations():
with open(translations_path, 'r', encoding='utf-8') as f:
translations = json.load(f)
user_locale = settings["settings"][0]["language"]
return lambda key: translations['languages'][key][user_locale]
_ = load_translations
def countDown():
print(4)
time.sleep(1)
print(3)
time.sleep(1)
print(2)
time.sleep(1)
print(_()("starting"))
def select_window(sfx):
global target
windows = gw.getAllTitles()
windows = list(set(windows))
windows = [win for win in windows if win != ""] # Remove empty list elements
windows = [win for win in windows if "AutoLyrePlayer" not in win] # remove itself from list
recommended = ["Genshin", "Oynatıcı", "Player"] # windows where these words appear
related_windows = []
for window in windows:
for recommend in recommended:
if recommend in window:
related_windows.append(window)
related_windows.sort()
if related_windows == []:
window = 0
target = None
else:
counter = 0
print(_()("select_window"))
for i in range(len(related_windows)):
counter += 1
print(counter, related_windows[i])
try:
choise = int(input(">> "))
except Exception as e:
print(e)
speak("error", sfx)
select_window()
return
if choise == 0:
target = None
return countDown()
else:
target = related_windows[choise-1]
window = gw.getWindowsWithTitle(target)[0]
print(_()("give_focus"))
while gw.getActiveWindowTitle() != target:
time.sleep(0.5)
speak("focused", sfx)
return target