This repository was archived by the owner on Dec 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebomberocr.py
107 lines (91 loc) · 4.27 KB
/
debomberocr.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 pyautogui
from PIL import Image
from pytesseract import *
import keyboard
import random
pyautogui.FAILSAFE = False
# DeBomber OCR Settings
triggerkey = "delete"
clrbonuskey = "home"
clearlistkey = "end"
sscoords = 540, 395, 45, 20 #this is my own region, use this script: https://github.com/xacvwe/DeBomberOCR/blob/main/region.py to change it!
textfile = "jklm_allwords.txt"
typespeed = 0.02
ocrpath = "C:\\path\\to\\Tesseract-OCR\\tesseract.exe"
ocrconfig = "-c tessedit_char_whitelist=ABCDEFGHIJKLMNOPQRSTUVWXYZ --psm 7 --oem 1"
# Debomber OCR Settings Help
# triggerkey - You can choose any trigger key to trigger DeBomberOCR and type words for you, key names is on this link https://github.com/xacvwe/DeBomberOCR/blob/main/triggerkeys.txt
# clrbonuskey - Resets the bonus letters list.
# clearlistkey - Clears the usedwords list.
# sscoords - Screenshots the bomb's letter prompt and converts it into a word containing those letters. it should look something like this: https://github.com/xacvwe/DeBomberOCR/blob/main/letters.png
# textfile - Where the OCR grabbs words containing the letters from sscoords.
# typespeed - Changes the typespeed, for faster epic dejavu thing use 0.00000000001 if you want but you might get banned
# ocrpath - Path for tesseract.exe, and also to make DeBomberOCR work.
# ocrconfig - Keep this config put if you don't know what it does to the script.
pytesseract.tesseract_cmd = ocrpath
print("DeBomberOCR is now running.")
usedwords = []
bonus = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V"]
wgeneration_limit = 25 # keep this on 25!
while True:
a = keyboard.read_key()
if a == clrbonuskey:
bonus.clear()
fillbonus = "ABCDEFGHIJKLMNOPQRSTUV"
for bonusfill in fillbonus:
bonus.append(bonusfill)
print("Resetted bonus letters.")
if a == clearlistkey:
usedwords.clear()
print("Cleared usedwords list.")
if a == triggerkey:
reqltr = random.choice(bonus)
print(reqltr)
scltr = pyautogui.screenshot(region=(sscoords))
scltr.save(r"./letters.png")
ltrimg = Image.open("letters.png")
ltrstr = pytesseract.image_to_string(ltrimg, config=ocrconfig)
n = ltrstr.split()
pltrs = ''.join(str(x) for x in n)
print('Letters: ' + pltrs)
if len(pltrs) == 0:
print("Cannot choose letters with none.")
if len(pltrs) != 0:
x = open(textfile, "r")
words = [w for w in x.read().split() if pltrs in w]
while True:
try:
a = random.choice(words)
except:
print("Cannot choose from an empty sequence (IndexError)")
if wgeneration_limit != 0:
if reqltr in a:
print(f"Word Accepted: {a}")
break
if reqltr not in a:
print(f"Word Declined: {a}")
wgeneration_limit -= 1
continue
if wgeneration_limit == 0:
wgeneration_limit += 25
print("Word Generation reached generation limit. Stopped Generating words to avoid DeBomberOCR from generating in an endless loop.")
break
used = [w for w in usedwords if a in w]
if used:
print("Word is already used!")
if not used:
print(f"Typing Word: {a}")
pyautogui.write(a, typespeed)
pyautogui.press('enter')
result = "".join(dict.fromkeys(a))
for letter in result:
letters = [w for w in bonus if letter in w]
if letters:
bonus.remove(letter)
if not letters:
print(f"Letter '{letter}' not in list")
if bonus == []:
fillbonus = "ABCDEFGHIJKLMNOPQRSTUV"
for bonusfill in fillbonus:
bonus.append(bonusfill)
print("Bonus Letters Left: " + ','.join(str(x) for x in bonus))