def __init__(self): self.PREFIX = PREFIX self.ready = False self.guild = None self.scheduler = AsyncIOScheduler() self.log = Log(r"C:\Users\woosal\Desktop\Chegg BOT X", "chegg.log") db.autosave(self.scheduler) super().__init__(command_prefix=PREFIX, OWNER_IDS=OWNER_IDS) super().__init__(command_prefix=PREFIX, owner_ids=OWNER_IDS)
def __init__(self): self.start = dt.now() self.log = Log(r"C:\Users\woosal\Desktop\Chegg BOT X", "chegg.log") self.downloadMail()
class SaveMail: def __init__(self): self.start = dt.now() self.log = Log(r"C:\Users\woosal\Desktop\Chegg BOT X", "chegg.log") self.downloadMail() def downloadMail(self): gmail = Gmail() try: messages = gmail.get_unread_inbox() if len(messages) > 0: print(f"{len(messages)} new message") msg = messages[0] link = extractLink(msg.plain) print(f"Question link: {link}") self.log.info(f"INIT-3:DOWNLOAD_MAIL:{link}") qId = findQuestionId(link) print(qId) createFolder(r"C:\Users\woosal\Desktop\Chegg BOT X\Downloads\{0}".format(qId)) fullPath = path.abspath(r"C:\Users\woosal\Desktop\Chegg BOT X\Downloads\{0}".format(qId)) soup = BeautifulSoup(msg.html, 'html.parser') imgs = soup.find_all('img') urls = [img['src'] for img in imgs] for i in range(1, len(urls) - 1): url = urls[i] name = f"{fullPath}\image{i}.png" try: res = get(url) file = open(name, "wb") file.write(res.content) except Exception as e: self.log.alert(f"DOWNLOAD_MAIL:Exception:{e}") pass try: f = open(r"{0}\aplain.txt".format(fullPath), "a", encoding="utf-8") f.write("".join(msg.plain.split("\n")[1:-13])) f.close() except Exception as e: self.log.alert(f"INIT-3:DOWNLOAD_MAIL:Exception:{e}") pass downloadTime = dt.now() - self.start self.log.info(f"INIT-3:DOWNLOAD_MAIL:Mail_Downloaded:{qId}") print(dt.now()) print(f"It took {downloadTime} seconds") msg.mark_as_read() self.log.info(f"INIT-3:DOWNLOAD_MAIL:Mail_Marked:{link}") else: pass except Exception as e: self.log.alert(f"INIT-3:DOWNLOAD_MAIL:Exception:{e}") pass
class Bot(BotBase): def __init__(self): self.PREFIX = PREFIX self.ready = False self.guild = None self.scheduler = AsyncIOScheduler() self.log = Log(r"C:\Users\woosal\Desktop\Chegg BOT X", "chegg.log") db.autosave(self.scheduler) super().__init__(command_prefix=PREFIX, OWNER_IDS=OWNER_IDS) super().__init__(command_prefix=PREFIX, owner_ids=OWNER_IDS) def setup(self): for cog in COGS: print(cog) self.load_extension(f"lib.cogs.{cog}") print(f"{cog} was loaded!") print("Setup Completed!") def run(self, version): self.VERSION = version print("Running Setup...") self.log.info("INIT_1:Setup") self.setup() with open("./lib/bot/token.0", "r", encoding="utf-8") as tf: self.TOKEN = tf.read() print("Running bot...") self.log.info("INIT_1:Run") super().run(self.TOKEN, reconnect=True) async def process_commands(self, message): ctx = await self.get_context(message, cls=Context) if ctx.command is not None and ctx.guild is not None: if self.ready: await self.invoke(ctx) else: await ctx.send( "I'm not listening to your commands you psycho, maybe later..." ) async def print_message(self): await self.stdout.send("Good Morning!") async def on_connect(self): print("BOT has been CONNECTED!") self.log.info("INIT_1:Connected") async def on_disconnect(self): print("BOT has been DISCONNECTED!") self.log.alert("INIT_1:Disconnected") async def on_error(self, err, *args, **kwargs): if err == "on_command_error": self.log.alert("INIT_1:on_command_error") else: channel = self.stdout self.log.alert(f"INIT_1:{err}:{channel}") raise async def on_command_error(self, ctx, exc): if isinstance(exc, CommandNotFound): return 1 elif hasattr(exc, "original"): pass else: raise exc async def on_ready(self): if not self.ready: self.channel = self.get_channel(801895525263343656) self.ready = True self.cogs_ready = Ready() self.guild = self.get_guild(801895525263343656) self.stdout = self.get_channel(801895525263343656) self.scheduler.add_job( self.print_message, CronTrigger(day_of_week=0, hour=12, minute=0, second=0)) self.scheduler.start() await bot.change_presence(activity=discord.Game( name="https://github.com/Chegg-BOT")) while self.cogs_ready.all_ready(): await sleep(0.5) else: self.log.info("INIT_1:Reconnect") print("BOT reconnected!") async def on_message(self, message): if not message.author.bot: await self.process_commands(message)
def __init__(self, bot): self.intents = discord.Intents.default() self.intents.members = True self.bot = bot self.log = Log(r"C:\Users\woosal\Desktop\Chegg BOT X", "chegg.log")
class Fun(Cog): def __init__(self, bot): self.intents = discord.Intents.default() self.intents.members = True self.bot = bot self.log = Log(r"C:\Users\woosal\Desktop\Chegg BOT X", "chegg.log") @command(name="commands", aliases=["info", "about"]) async def help(self, ctx): self.log.command(f"{ctx.message.author.id}:commands") embed = discord.Embed(title="Chegg BOT", url="https://cheggbot.woosal.com/", description="Unblur the answers of the Chegg questions, and get receive them.", color=0xfbc041) embed.set_author(name="woosal", url="https://woosal.com/", icon_url="https://woosal.com/1337/woosal1337-AxcOjfpPCjYo2aMU9s05XvXnLk3SGXC67oJq7CZ6d0TCTRPzMKZ8D9q5g7W4fIdWwmwRVQHdYvffkr16RsEdD0Y1Y.png") embed.set_thumbnail(url="https://woosal.com/1337/cheggwpfullblacklogoleftnobg.png") embed.add_field(name="Add Your Email", value="+addmail [email protected]", inline=False) embed.add_field(name="Search For The Question", value="+chegg URL", inline=False) embed.add_field(name="Commands", value="+commands", inline=False) embed.add_field(name="Your Current Mail Info", value="+mymail", inline=False) embed.add_field(name="Update Your Mail to New Mail", value="+updatemail [email protected]", inline=False) embed.add_field(name="Delete Your Mail Completely", value="+deletemail", inline=False) embed.add_field(name="Want a new feature?", value="*****@*****.**", inline=False) embed.set_footer(text="Star the project on GitHub: https://github.com/woosal1337/Chegg-Discord-BOT") await ctx.send(embed=embed) return True @command(name="addmail", aliases=["adduser"]) async def add_mail(self, ctx, *mails): if len(mails) == 1: mail = mails[0] self.log.command(f"{ctx.message.author.id}:addmail:{mail}:") await ctx.message.delete() ############################################# newUser = [str(ctx.message.author.id), mail] print("New User: "******"Such user already registered with the mail of {0}".format(newUserResMail)) try: await ctx.author.send("Such user already registered with the mail of {0}".format(newUserResMail)) except: await ctx.send("Such user already registered with this mail address") return True # User is registering for the first time else: print(addUser(newUser[0], newUser[1])) print("Mail has been added successfully!") try: await ctx.author.send("Your mail has been successfully added!") except: await ctx.send("Your mail has been successfully added!") print("\n") return True ############################################# else: print("BBBBB") try: await ctx.author.send("Dear {0}, please enter a valid mail address!".format(ctx.message.author.name)) except: await ctx.send("Dear {0}, please enter a valid mail address!".format(ctx.message.author.name)) @command(name="updatemail", aliases=["newmail", "mainmail", "changemail"]) async def update_mail(self, ctx, *mails): await ctx.message.delete() if len(mails) == 1: mail = mails[0] self.log.command( f"{ctx.message.author.id}:updatemail:{getUser(str(ctx.message.author.id))['mail']}:to:{mail}") # +updatemail [email protected] 1 userid = str(ctx.message.author.id) if getUser(userid) != None: try: await ctx.author.send("Your email has been updated to {0}".format(mail)) except: await ctx.send("Your email has been updated successfully!") print(updateMail(userid, mail)) return True else: try: await ctx.author.send( "This user has not registered any mails yet, please use ```+addmail [email protected]``` to create your account!") except: await ctx.send( "This user has not registered any mails yet, please use ```+addmail [email protected]``` to create your account!") return True else: try: await ctx.author.send("Dear {0}, please enter a valid mail address!".format(ctx.message.author.name)) except: await ctx.send("Dear {0}, please enter a valid mail address!".format(ctx.message.author.name)) @command(name="mymail", aliases=["currentmail", "mycurrentmail", "savedmail", "mysavedmail", "mail"]) async def current_mail(self, ctx): self.log.command(f"{ctx.message.author.id}:mymail:{getUser(ctx.message.author.id)['mail']}") await ctx.message.delete() userid = str(ctx.message.author.id) if getUser(userid) != None: try: await ctx.author.send( "Your current saved mail to your Discord account is ```{0}``` You can update it anytime you want by using ```+updatemail [email protected]```".format( getUserMail(userid))) except: await ctx.send("You have to allow direct messages to use this feature!") print( "Your current saved mail to your Discord account is ```{0}``` You can update it anytime you want by using ```+updatemail [email protected]```".format( getUserMail(userid))) return True else: try: await ctx.author.send( "This user has not registered any mails yet, please use ```+addmail [email protected]``` to create your account") except: await ctx.send( "This user has not registered any mails yet, please use ```+addmail [email protected]``` to create your account") return True @command(name="deletemail", aliases=["purgemail", "delete", "removemail", "removeme", "purgeme", 'deleteuser']) async def delete_user(self, ctx): self.log.command(f"{ctx.message.author.id}:deletemail:{getUser(ctx.message.author.id)['mail']}") await ctx.message.delete() print("Delete user request was received.") userid = str(ctx.message.author.id) if getUser(userid) != None: print(deleteUser(userid)) try: await ctx.author.send("Dear {0}, your mail was removed!".format(ctx.message.author.name)) except: await ctx.send("Dear {0}, your mail was removed!".format(ctx.message.author.name)) print("{0}'s mail was removed!".format(ctx.message.author)) return True else: try: await ctx.author.send( "Dear {0}, your have not even registered yet, please consider registering at first by using the command: ```+addmail [email protected]```".format( ctx.message.author.name)) except: await ctx.send( "Dear {0}, your have not even registered yet, please consider registering at first by using the command: ```+addmail [email protected]```".format( ctx.message.author.name)) print("{0} have not registered yet".format(ctx.message.id)) return True @command(name="chegg", aliases=["check", "cheggapi", "search"]) async def chegg_answer(self, ctx, *links): await ctx.message.delete() if len(links) == 1: link = links[0] self.log.command(f"{ctx.message.author.id}:chegg:{link}") userid = str(ctx.message.author.id) newUserRes = getUser(userid) if newUserRes != None: if "chegg.com" in link: newUserResMail = newUserRes["mail"] try: await ctx.author.send("I am searching for the answer, please give me a few seconds!") except: await ctx.send("I am searching for the answer, please give me a few seconds!") print("User: {0}; Link:{1}".format(ctx.message.author, link)) print(getLink(newUserResMail, str(link))) try: await ctx.author.send( "Dear {1}, I am sending the answer to {0}, you will get it in a few minutes!".format( newUserResMail, ctx.message.author.name)) except: await ctx.send( "Dear {0}, I am sending the answer to your registered mail!".format(ctx.message.author.name)) return True else: try: await ctx.author.send( "Dear {0}, Please use only official Chegg links, this link is not recognized!".format( ctx.message.author.name)) except: await ctx.send( "Dear {0}, Please use only official Chegg links, this link is not recognized!".format( ctx.message.author.name)) print("Wrong link was used: {0}".format(link)) return True else: try: await ctx.author.send( "You have not added your email to our database, make sure to add your own email by using```+addmail [email protected]```") except: await ctx.send( "You have not added your email to our database, make sure to add your own email by using```+addmail [email protected]```") pass print(f"{ctx.message.author.id} has not registered a mail to our database yet.") return True else: try: await ctx.author.send( "Dear {0}, Please use only official Chegg links, this link is not recognized!".format( ctx.message.author.name)) except: await ctx.send( "Dear {0}, Please use only official Chegg links, this link is not recognized!".format( ctx.message.author.name)) @command(name="cheggdm", aliases=["dmchegg", "pmchegg", "cheggpm"]) async def chegg_send_dm(self, ctx, *links): await ctx.message.delete() if len(links) == 1: link = links[0] self.log.command(f"{ctx.message.author.id}:cheggdm:{link}") userid = ctx.message.author.id if len(getQuestion(userid)) == 0: if ctx.message.author.id in ALLOWED: if "chegg.com" in link: questionid = findQuestionId(link) print(addQuestion(userid, questionid)) print(getLink("*****@*****.**", link)) self.log.info(f"{ctx.message.author.id}:question_added:{questionid}") try: await ctx.author.send("You will get your answers in a few minutes!") except: await ctx.send("You have to allow direct messages to get answers!") else: try: await ctx.author.send("You do not have permissions to do this action!") except: pass else: try: await ctx.author.send("Please, wait for your previous request to be sent!") #await ctx.author.send("Please, wait for your previous request to be sent!") except: pass else: try: await ctx.author.send( "Dear {0}, Please use only official Chegg links, this link is not recognized!".format( ctx.message.author.name)) except: pass @command(name="deletequestion") async def delete_question(self, ctx): self.log.command(f"{ctx.message.author.id}:deletequestion:{getQuestion(ctx.message.author.id)}") await ctx.message.delete() userid = ctx.message.author.id deleteQuestion(str(userid)) try: await ctx.author.send( "Dear {0}, your question request deleted successfully".format(ctx.message.author.name)) except: await ctx.send( "Dear {0}, your question request deleted successfully".format(ctx.message.author.name)) @command(name="usersdb", aliases=["totalusers", "currentusers"]) async def users_db(self, ctx): await ctx.message.delete() if ctx.message.author.id in OWNERS: for i in OWNERS: user = await self.bot.fetch_user(int(i)) try: await user.send( "There are {0} users saved in the database using the bot!".format(len(fetchAllUsers()), len(self.bot.guilds))) except: pass else: await ctx.send("You are not the owner of the bot! Only owners can access this command!") self.log.alert(f"{ctx.message.author.id}:usersdb_command") @command(name="usersdc", aliases=["usersdiscord"]) async def users_dc(self, ctx): await ctx.message.delete() if ctx.message.author.id in OWNERS: for i in OWNERS: user = await self.bot.fetch_user(int(i)) userCount = 0 for j in self.bot.guilds: userCount += j.member_count try: await user.send( "There are {0} users in {1} servers using the bot!".format(userCount, len(self.bot.guilds))) except: pass else: await ctx.send("You are not the owner of the bot! Only owners can access this command!") self.log.alert(f"{ctx.message.author.id}:usersdc_command") @command(name="servers", aliases=["server"]) async def total_servers(self, ctx): await ctx.message.delete() if ctx.message.author.id in OWNERS: for i in OWNERS: user = await self.bot.fetch_user(int(i)) try: await user.send("BOT is currently in {0} servers!".format(len(self.bot.guilds))) except: pass else: await ctx.send("Dear {0}, you are not the owner of the bot! Only owners can access this command!".format(ctx.message.author.name)) self.log.alert(f"{ctx.message.author.id}:servers_command")
class Bot(BotBase): def __init__(self): self.PREFIX = PREFIX self.ready = False self.guild = None self.scheduler = AsyncIOScheduler() self.log = Log(r"C:\Users\woosal\Desktop\Chegg BOT X", "chegg.log") db.autosave(self.scheduler) super().__init__(command_prefix=PREFIX, OWNER_IDS=OWNER_IDS) super().__init__(command_prefix=PREFIX, owner_ids=OWNER_IDS) def setup(self): for cog in COGS: print(cog) self.log.info(cog) self.load_extension(f"lib.cogs.{cog}") print(f"{cog} was loaded!") self.log.info(f"{cog} was loaded!") print("Setup Completed!") self.log.info("Setup Completed!") def run(self, version): self.VERSION = version print("Running Setup...") self.log.info("Running Setup...") self.setup() with open("./lib/bot/token.0", "r", encoding="utf-8") as tf: self.TOKEN = tf.read() print("Running bot...") self.log.info("Running bot...") super().run(self.TOKEN, reconnect=True) async def process_commands(self, message): ctx = await self.get_context(message, cls=Context) if ctx.command is not None and ctx.guild is not None: if self.ready: await self.invoke(ctx) else: pass #await ctx.send("I'm not listening to your commands you psycho, maybe later...") async def print_message(self): await self.stdout.send("Good Morning!") async def on_connect(self): print("BOT has been CONNECTED!") self.log.info("BOT has been CONNECTED!") async def on_disconnect(self): print("BOT has been DISCONNECTED!") self.log.alert("BOT has been DISCONNECTED!") async def on_error(self, err, *args, **kwargs): if err == "on_command_error": await args[0].send("Something went wrong!") else: channel = self.stdout await channel.send( "Dude your code freaking sucks, and error occured right here!") raise async def on_command_error(self, ctx, exc): if isinstance(exc, CommandNotFound): pass elif hasattr(exc, "original"): raise exc.original else: raise exc async def on_ready(self): # Set Channel ID # self.channelName = self.get_channel(CHANNEL_ID) # Set Guild ID # self.guildName = self.get_guild(CHANNEL_ID) # Sending message to the channel # await self.stdout.send("Now online!") if not self.ready: #799828505910575116 self.channel = self.get_channel(801895525263343656) self.ready = True self.cogs_ready = Ready() self.guild = self.get_guild(801895525263343656) self.stdout = self.get_channel(801895525263343656) self.scheduler.add_job( self.print_message, CronTrigger(day_of_week=0, hour=12, minute=0, second=0)) self.scheduler.start() while self.cogs_ready.all_ready(): await sleep(0.5) downloadsPath = r"C:\Users\woosal\Desktop\Chegg BOT X\Downloads" while True: time.sleep(1) scannedQuestionId = scanDir(downloadsPath) if scannedQuestionId != None: print("Question Found!!") time.sleep(7) askerUserId = getUIDByQuestionID(scannedQuestionId) print(askerUserId) if askerUserId == None: deleteDir(r"{0}\{1}".format(downloadsPath, scannedQuestionId)) else: user = await self.fetch_user(int(askerUserId)) print(user) files = scanTheDir(r"{0}\{1}".format( downloadsPath, scannedQuestionId)) for file in files: print(file) if file[-4:] == ".txt": # r"{0}\aplain.txt".format(path): f = open(file, "r", encoding="utf-8") msg = f.read() f.close() try: await user.send(msg) except: await user.send(file=discord.File(file)) else: await user.send(file=discord.File(file)) time.sleep(1) deleteDir(r"{0}\{1}".format(downloadsPath, scannedQuestionId)) deleteQuestion(askerUserId) else: print("Nothing found, searching again!") else: print("BOT reconnected!") self.log.alert("BOT reconnected!") async def on_message(self, message): if not message.author.bot: await self.process_commands(message)