-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
108 lines (81 loc) · 2.51 KB
/
main.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
import time
from selenium import webdriver
from interactor import Bot
from miscellaneous import formatted_time, set_environment
from settings import Settings
if set_environment():
print("Enter your input in config\\config.json before running again.")
exit(0)
global_settings = Settings()
global_settings.load_config()
print(global_settings.briefing())
print('Setting driver options.')
options = webdriver.ChromeOptions()
options.add_argument('-headless')
options.add_argument('--log-level=3')
# Chrome specific.
service = webdriver.ChromeService(log_output='chrome-driver.log')
print('Loading web driver.')
driver = webdriver.Chrome(options=options, service=service)
driver.implicitly_wait(10)
print('Setting bot.')
bot = Bot(driver, global_settings)
print('Loading login page.')
driver.get("https://discord.com/login")
# Auto login.
h = 1
while h <= global_settings.login_attempts:
try:
print(f'Login attempt ({h}/{global_settings.login_attempts}): ', end='')
bot.perform_login()
print('Success.')
break
except Exception as e:
print('Failure.')
print('Refreshing login page.')
driver.refresh()
h += 1
if h > global_settings.login_attempts:
print('Login could not be performed.')
exit(1)
# Target server selection.
h = 1
while h <= global_settings.selection_attempts:
try:
print(f'Server selection attempt ({h}/{global_settings.selection_attempts}): ', end='')
bot.select_server()
print('Success.')
break
except Exception as e:
print('Failure.')
print('Refreshing channels page.')
driver.refresh()
h += 1
if h > global_settings.selection_attempts:
print('Target server could not be selected.')
exit(1)
# Initializing timer.
print('Starting timer.')
start_time = time.time()
# Search and deletion of messages.
nil_count, progress = 0, 0
while nil_count <= global_settings.nil_tolerance and progress < global_settings.target_count:
print(f'\nNew iteration of search and delete.')
driver.refresh()
try:
# Inform the bot with the right number of messages to delete.
status = bot.search_and_delete(global_settings.target_count - progress)
except Exception as e:
print('\nUnexpected error:', e)
break
if status == 0:
# Total iterations with zero messages deleted.
nil_count += 1
else:
# Total messages deleted.
progress += status
elapsed_time = time.time() - start_time
print(f'\nTotal progress: {progress}\nZero status occurences: {nil_count}\nElapsed time: {formatted_time(int(elapsed_time))}')
# Finishing session.
print('\nInteraction finished.\nClosing the driver.')
driver.quit()