diff --git a/Pipfile b/Pipfile index e76ebed..80d024f 100644 --- a/Pipfile +++ b/Pipfile @@ -22,6 +22,7 @@ beautifulsoup4 = "*" requests = "*" html5lib = "*" tldextract = "*" +selenium = "*" [dev-packages] lxml = "*" diff --git a/src/cogs/weeb.py b/src/cogs/weeb.py new file mode 100644 index 0000000..f5910d7 --- /dev/null +++ b/src/cogs/weeb.py @@ -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)}') diff --git a/src/run.py b/src/run.py index c6046e7..3d4a3f5 100644 --- a/src/run.py +++ b/src/run.py @@ -21,25 +21,30 @@ def get_prefix(bot, message): return u.settings['prefixes'].get(message.guild.id, u.config['prefix']) return u.config['prefix'] +intents = d.Intents.default() +intents.members = True bot = cmds.Bot( + intents=intents, command_prefix=get_prefix, self_bot=u.config['selfbot'], description='Modufur - A booru bot with a side of management and automated tasking' - '\nMade by @Myned#3985') + '\nMade by @Myned#3985' +) @bot.event async def on_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 ( tools.Utils(bot), owner.Bot(bot), management.Admin(bot), info.Info(bot), - booru.MsG(bot)): + booru.MsG(bot), + weeb.Weeb(bot)): bot.add_cog(cog) u.cogs[type(cog).__name__] = cog print(f'COG : {type(cog).__name__}')