-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWS3K.py
132 lines (80 loc) · 2.98 KB
/
WS3K.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# WS3K by Alex Arbuckle #
# Import <
from json import load, dump
from discord import Intents
from selenium import webdriver
from time import sleep as timeSleep
from discord.ext.commands import Bot
from asyncio import sleep as asyncioSleep
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
# >
# Declaration <
WS3K = Bot(command_prefix = '', intents = Intents.all())
username, password = '', ''
token = ''
# >
async def jsonLoad():
''' '''
with open('WS3K.json', 'r') as fileVariable:
return load(fileVariable)
async def jsonDump(arg):
''' arg : dict '''
with open('WS3K.json', 'w') as fileVariable:
dump(arg, fileVariable, indent = 4)
@WS3K.event
async def on_ready():
''' '''
# Webdriver <
options = Options()
options.headless = True
driver = webdriver.Chrome(ChromeDriverManager().install(), options = options)
# >
# Logging In <
setting = await jsonLoad()
driver.get('https://discord.com/login'), timeSleep(1)
driver.find_element_by_xpath(setting['usernamePath']).send_keys(username), timeSleep(0.2)
driver.find_element_by_xpath(setting['passwordPath']).send_keys(password), timeSleep(0.2)
driver.find_element_by_xpath(setting['loginPath']).click(), timeSleep(5)
# >
# Algorithm <
while (True):
setting = await jsonLoad()
for channel in setting['channel']:
try:
driver.get(channel), timeSleep(1)
driver.find_element_by_xpath(setting['checkPath'])
await WS3K.get_user(setting['authorId']).send(':bell: {}'.format(channel))
await asyncioSleep(setting['alertRate'])
except Exception as e:
print(e)
await asyncioSleep(setting['sleepRate'])
await asyncioSleep(setting['sleepRate'])
# >
@WS3K.command(aliases = ['add', 'Add'])
async def addChannel(ctx, arg):
''' '''
dictVariable = await jsonLoad()
if (arg not in dictVariable['channel']):
dictVariable['channel'].append(arg)
await jsonDump(dictVariable)
await ctx.channel.send(f'Channel {arg} was added.', delete_after = 60)
else:
await ctx.channel.send(f'Channel {arg} already exists.', delete_after = 60)
@WS3K.command(aliases = ['remove', 'Remove'])
async def removeChannel(ctx, arg):
''' '''
dictVariable = await jsonLoad()
if (arg in dictVariable['channel']):
dictVariable['channel'].remove(arg)
await jsonDump(dictVariable)
await ctx.channel.send(f'Channel {arg} was removed.', delete_after = 60)
else:
await ctx.channel.send(f'Channel {arg} does not exist.', delete_after = 60)
@WS3K.command(aliases = ['show', 'Show'])
async def showChannel(ctx):
''' '''
dictVariable = await jsonLoad()
strVariable = ''.join(f'{i}\n' for i in dictVariable['channel'])
await ctx.channel.send(strVariable, delete_after = 60)
WS3K.run(token)