1
0
Fork 0
mirror of https://github.com/myned/modufur.git synced 2024-12-24 22:27:28 +00:00

Add personal temp notifications

This commit is contained in:
Myned 2020-10-13 02:23:23 -04:00
parent f2f7ee4eae
commit 3df2438c79
No known key found for this signature in database
GPG key ID: D42B2DAADE7D2AB5
3 changed files with 65 additions and 2 deletions

View file

@ -22,6 +22,7 @@ beautifulsoup4 = "*"
requests = "*" requests = "*"
html5lib = "*" html5lib = "*"
tldextract = "*" tldextract = "*"
selenium = "*"
[dev-packages] [dev-packages]
lxml = "*" lxml = "*"

61
src/cogs/weeb.py Normal file
View file

@ -0,0 +1,61 @@
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
import asyncio
import traceback as tb
from discord.ext import commands as cmds
from utils import utils as u
class Weeb(cmds.Cog):
def __init__(self, bot):
self.bot = bot
self.weebing = False
with open('id.json') as f:
self.id = int(f.readline())
print('LOADED : id.json')
if not self.weebing:
self.weebing = True
self.bot.loop.create_task(self.start())
print('STARTED : weebing')
async def refresh(self, browser, urls):
message = ''
for item, url in urls.items():
browser.get(url)
status = browser.find_elements_by_css_selector('#addToCartText-product-template')[0].text
if status != 'SOLD OUT':
message += f'{item} is in stock!\n{url}\n'
return message
async def start(self):
try:
opts = Options()
opts.headless = True
browser = Chrome(executable_path='/usr/bin/chromedriver', options=opts)
urls = {
'Novelties': 'https://switchmod.net/collections/ended-gbs/products/gmk-metaverse-2?variant=31671816880208',
'Royal': 'https://switchmod.net/collections/ended-gbs/products/gmk-metaverse-2?variant=31671816945744'
}
while self.weebing:
message = await self.refresh(browser, urls)
if message:
await self.bot.get_user(self.id).send(message)
await self.bot.get_user(u.config['owner_id']).send('Message sent')
browser.quit()
self.weebing = False
await asyncio.sleep(60)
except Exception as e:
tb.print_exc()
await self.bot.get_user(u.config['owner_id']).send(f'! ERROR !\n\n{repr(e)}')

View file

@ -32,14 +32,15 @@ bot = cmds.Bot(
@bot.event @bot.event
async def on_ready(): async def on_ready():
if not checks.ready: if not checks.ready:
from cogs import booru, info, management, owner, tools from cogs import weeb, booru, info, management, owner, tools
for cog in ( for cog in (
tools.Utils(bot), tools.Utils(bot),
owner.Bot(bot), owner.Bot(bot),
management.Admin(bot), management.Admin(bot),
info.Info(bot), info.Info(bot),
booru.MsG(bot)): booru.MsG(bot),
weeb.Weeb(bot)):
bot.add_cog(cog) bot.add_cog(cog)
u.cogs[type(cog).__name__] = cog u.cogs[type(cog).__name__] = cog
print(f'COG : {type(cog).__name__}') print(f'COG : {type(cog).__name__}')