def exit_the_programm(self): answer = QMessageBox.question(self, 'Выход', 'Вы уверены, что хотите выйти?', QMessageBox.Yes, QMessageBox.No) if answer == QMessageBox.Yes: trio_run(self.api.api_logout) sys_exit(self.destroy())
def diary(self, diary, api): '''Преоброзавание json в очищенный словарь (json -->> dict) Parameter: diary (dict): json dictionary with extra data Return: dict:Returning dict only with the data you need Days, lessons, lesson start and end time, marks ''' clear_diary = {} weekdays = diary.weekDays for index, day in enumerate(weekdays): dayoftheweek_string = self.daysoftheweek[index] clear_diary[dayoftheweek_string] = {} for lesson in day.lessons: lesson_name = self.lesson(lesson.subjectName) while lesson_name in clear_diary[dayoftheweek_string]: lesson_name += ' ' clear_diary[dayoftheweek_string][lesson_name] = {} diary_lesson = clear_diary[dayoftheweek_string][lesson_name] diary_lesson['number'] = lesson.number diary_lesson['time'] = (lesson.startTime, lesson.endTime) if None != lesson.assignments: diary_lesson['homework'] = [] for assignment in lesson.assignments: if assignment.mark != None: diary_lesson['mark'] = assignment.mark.mark api.id_ = assignment.id lesson_attachment = [] if assignment.mark == None and assignment.weight == 0: lesson_attachment = trio_run(api.get_attachments) if lesson_attachment != []: lesson_attachment = lesson_attachment[0] for attachment in lesson_attachment.attachments: api.attachment = attachment file_bytes = trio_run(api.download_file) if file_bytes != False: with open(f'./files/{file_bytes.name}', 'wb') as file: file.write(file_bytes.getbuffer()) id_ = self.db.add_file( attachment, dayoftheweek_string, lesson_name) while type(id_) != int: id_ = id_[0] diary_lesson['file'] = id_ for homework in lesson.assignments: diary_lesson['homework'].append( homework.assignmentName) if diary_lesson['homework'] == []: diary_lesson.pop('homework') return clear_diary
async def verify(ctx, content=""): """Подтвердить свой аккант HTB (Запуск после !account)""" if str(ctx.channel.type) == "private": if content: verify_rep = trio_run(htbot.verify_user, ctx.author.id, content) if verify_rep == "already_in": await ctx.send("You already have verified your HTB account.") elif verify_rep == "wrong_id": await ctx.send("This Account Identifier does not work.\nAre you sure you followed the instructions correctly ?") else: guilds = bot.guilds for guild in guilds: if guild.name == cfg.discord['guild_name']: roles = guild.roles role_name = cfg.roles[verify_rep.lower()] for role in roles: if role.name == role_name: member = guild.get_member(ctx.author.id) await member.add_roles(role) embed = discord.Embed(title="Roles added", description=cfg.roles[verify_rep.lower()], color=0x14ff08) await ctx.send(embed=embed) else: await ctx.send("Je crois que tu as oublié ton Account Identifier.") await send_verif_instructions(ctx.author) else: if content: await ctx.message.delete() await ctx.send("😱 N'envoie pas ça ici {} !\nViens donc en privé, je t'ai envoyé les instructions.".format(ctx.author.mention)) await send_verif_instructions(ctx.author) else: await ctx.send("{} Viens en privé, je t'ai envoyé les instructions.".format(ctx.author.mention)) await send_verif_instructions(ctx.author)
def show_announcements(self): announcements = [] self.showMinimized() for announcement in trio_run(self.api.announcements): announcement = self.clear.announcement(announcement, self.api) announcements.append(announcement) announcement_window = AnnouncementSelector(self, announcements) announcement_window.show()
async def get_user(ctx, name=""): """Stalk your competitors""" if name: htb_id = trio_run(htbot.htb_id_by_name, name) if htb_id: embed = await thread_get_user(str(htb_id)) await ctx.send(embed=embed) else: await ctx.send("Utilisateur non trouvé.") else: await ctx.send("T'as pas oublié un truc ? :tired_face:")
async def get_user(ctx, name=""): """Информация о пользователе (Example: >get_user GreyParzival)""" if name: htb_id = trio_run(htbot.htb_id_by_name, name) if htb_id: embed = await thread_get_user(str(htb_id)) await ctx.send(embed=embed) else: await ctx.send("Utilisateur non trouvé.") else: await ctx.send("T'as pas oublié un truc ? :tired_face:")
def __init__(self, login, password): self.week = None self.attachment = None self.id_ = None week_start, week_end = self.week_now() self.current_week_start = week_start self.current_week_end = week_end self.api = NetSchoolAPIPlus(URL) self.login = login self.password = password while trio_run(self.api_login): pass
def fill_the_tables(self, week=''): self.uncolor() cheat_mode = self.settings.cheat_mode() if week != '': self.api.week = week diary = self.cheat.up_marks( self.clear.diary(trio_run(self.api.diary), self.api), cheat_mode) self.api.week = None else: diary = self.cheat.up_marks( self.clear.diary(trio_run(self.api.diary), self.api), cheat_mode) for day in self.days_and_widgets: self.days_and_widgets[day].clear() self.days_and_widgets[day].setColumnCount(4) self.days_and_widgets[day].setRowCount(7) self.set_headers() vertical_headers = [] if day in diary: for index, lesson in enumerate(diary[day]): name = lesson lesson = diary[day][lesson] self.days_and_widgets[day].setItem( index, 0, QTableWidgetItem(' | '.join(lesson['time']))) self.days_and_widgets[day].setItem(index, 1, QTableWidgetItem(name)) vertical_headers.append(str(lesson['number'])) if 'homework' in lesson: self.days_and_widgets[day].setItem( index, 2, QTableWidgetItem('\n'.join(lesson['homework']))) if 'mark' in lesson: self.days_and_widgets[day].setItem( index, 3, QTableWidgetItem(str(lesson['mark']))) while len(vertical_headers) < 7: vertical_headers.append('0') self.days_and_widgets[day].setVerticalHeaderLabels(vertical_headers) self.color_files(diary)
async def get_chall(ctx, *, name=""): """Информация по таску (Example: !get_chall Ropme)""" if name: chall_status = htbot.check_chall(name) if chall_status: chall = trio_run(htbot.get_chall, name) if chall: await ctx.send("", embed=chall["embed"]) else: await ctx.send("Erreur.") else: await ctx.send("Таск не найден.") else: await ctx.send("Tu n'as pas précisé le challenge.")
async def get_chall(ctx, *, name=""): """Get info on a chall""" if name: chall_status = htbot.check_chall(name) if chall_status: chall = trio_run(htbot.get_chall, name) if chall: await ctx.send("", embed=chall["embed"]) else: await ctx.send("Erreur.") else: await ctx.send("Ce challenge n'existe pas.") else: await ctx.send("Tu n'as pas précisé le challenge.")
def announcement(self, announcement_, api): result = {} result['name'] = str(announcement_.name) result['author'] = str(announcement_.author.fio) result['description'] = str( self.announcement_description(announcement_.description)) if announcement_.attachments != []: api.attachment = announcement_.attachments[0] file_bytes = trio_run(api.download_file) if file_bytes != False: with open(f'./files/{file_bytes.name}', 'wb') as file: file.write(file_bytes.getbuffer()) result['attachment'] = f'./files/{file_bytes.name}' else: path = f'./files/{announcement_.attachments[0].originalFileName}' result['attachment'] = path return result
async def verify(ctx, content=""): """Verify your HTB account""" if content: await ctx.message.delete() verify_rep = trio_run(htbot.verify_user, ctx.author.id, content) if verify_rep == "already_in": await ctx.send("You already have verified your HTB account.") elif verify_rep == "wrong_id": await ctx.send( "This Account Identifier does not work.\nAre you sure you followed the instructions correctly ?" ) else: member = ctx.message.author role = discord.utils.get(member.guild.roles, name='Member') await member.add_roles(role) embed = discord.Embed(title="Roles added", description='Member', color=0x14ff08) await ctx.send(embed=embed) else: await send_verif_instructions(ctx)
def do_login(self): login = self.clear.login_or_password(self.login_input.text()) password = self.clear.login_or_password(self.password_input.text()) try: if self.verify(login) and self.verify(password): self.diary = trio_run(ESchool(login, password).diary) except WrongCredentialsError as error: self.show_error(WrongLoginDataException().text) except Exception as error: try: if str(error.text) == '': self.show_error(str(BannedAPIException().text)) else: self.show_error(str(error.text)) except: if str(error) == '': self.show_error(str(BannedAPIException().text)) else: self.show_error(str(error)) else: self.add_user(login, password, self.diary) self.start_main_menu(login, password)
async def make_embed(ctx, target, box=False, chall=False): guilds = bot.guilds bot_guild = False for guild in guilds: if guild.name == cfg.discord['guild_name']: bot_guild = guild if not bot_guild: await ctx.send("Erreur.") return False if box: box = trio_run( functools.partial(htbot.get_progress, target, box=True)) embed = discord.Embed(title="Progress | " + box["name"], color=0x9acc14) embed.set_thumbnail(url=box["thumbnail"]) working_on = "" if box["working_on"]: for user in box["working_on"]: discord_user = bot_guild.get_member(user) working_on += discord_user.display_name + "\n" else: working_on = "*Nobody*" embed.add_field(name="Working on", value=working_on) user_owns = "" if box["user_owns"]: for user in box["user_owns"]: discord_user = bot_guild.get_member(user) user_owns += discord_user.display_name + "\n" else: user_owns = "*Nobody*" embed.add_field(name="User", value=user_owns) root_owns = "" if box["root_owns"]: for user in box["root_owns"]: discord_user = bot_guild.get_member(user) root_owns += discord_user.display_name + "\n" else: root_owns = "*Nobody*" embed.add_field(name="Root", value=root_owns) return embed elif chall: chall = trio_run( functools.partial(htbot.get_progress, target, chall=True)) embed = discord.Embed(title="Progress | {} ({})".format( chall["name"], chall["category"]), color=0x9acc14) working_on = "" if chall["working_on"]: for user in chall["working_on"]: discord_user = bot_guild.get_member(user) working_on += discord_user.display_name + "\n" else: working_on = "*Nobody*" embed.add_field(name="Working on", value=working_on) chall_owns = "" if chall["chall_owns"]: for user in chall["chall_owns"]: discord_user = bot_guild.get_member(user) chall_owns += discord_user.display_name + "\n" else: chall_owns = "*Nobody*" embed.add_field(name="Owns", value=chall_owns) return embed
async def work_on(ctx, *, content=""): """Do this command when you start a new box""" # Args parser args = content.split() count = 0 box = False chall = False query = [] target_flag = False while count < len(args): if (args[count] == "-b" or args[count] == "--box") and not box: box = True if target_flag: break else: count += 1 continue elif (args[count] == "-c" or args[count] == "--chall") and not chall: chall = True if target_flag: break else: count += 1 continue else: if not target_flag: target_flag = True query.append(args[count]) count += 1 if (box and chall) or (not box and not chall): await ctx.send("Erreur.") return False target = " ".join(query) if target: if box: #Si le nom de la box est précisé box_name = target.lower() box_status = htbot.check_box(box_name) if box_status: status = trio_run( functools.partial(htbot.work_on, target, ctx.author.id, box=True)) if not status: print("Erreur.") return False guilds = bot.guilds for guild in guilds: if guild.name == cfg.discord['guild_name']: channels = guild.channels for channel in channels: if channel.name == box_name: if status == "success": await ctx.send( "Le channel {} est à ta disposition, bonne chance ! ❤" .format(channel.mention)) return True elif status == "already_owned": await ctx.send( "Tu as déjà terminé cette box, mais le channel {} reste à ta disposition ❤" .format(channel.mention)) return True #Si le channel n'existe pas encore categories = guild.categories if box_status == "active": for category in categories: if "box-active" in category.name.lower(): await guild.create_text_channel( name=box_name, category=category) channels = guild.channels for channel in channels: if channel.name == box_name: if status == "success": await ctx.send( "J'ai créé le channel {}, il est à ta disposition ! Bonne chance ❤" .format(channel.mention)) elif status == "already_owned": await ctx.send( "Tu as déjà terminé cette box, mais j'ai quand même créé le channel {} ! Il est à ta disposition, bonne chance ❤" .format(channel.mention)) box = await thread_get_box( box_name, matrix=True) await channel.send( "✨ Channel créé ! {}".format( ctx.author.mention)) await channel.send( "", embed=box["embed"]) return True elif box_status == "retired": for category in categories: if "box-retired" in category.name.lower(): await guild.create_text_channel( name=box_name, category=category) channels = guild.channels for channel in channels: if channel.name == box_name: if status == "success": await ctx.send( "J'ai créé le channel {}, il est à ta disposition ! Bonne chance ❤" .format(channel.mention)) elif status == "already_owned": await ctx.send( "Tu as déjà terminé cette box, mais j'ai quand même créé le channel {} ! Il est à ta disposition, bonne chance ❤" .format(channel.mention)) box = await thread_get_box( box_name, matrix=True) await channel.send( "✨ Channel créé ! {}".format( ctx.author.mention)) await channel.send( "", embed=box["embed"]) return True else: await ctx.send("Cette box n'existe pas.") elif chall: chall_status = htbot.check_chall(target) if chall_status: status = trio_run( functools.partial(htbot.work_on, target, ctx.author.id, chall=True)) if not status: print("Erreur.") return False elif status == "success": await ctx.send("Bonne chance {} ! ❤".format( ctx.author.mention)) return True elif status == "already_owned": await ctx.send("Tu as déjà terminé ce challenge !") return True else: await ctx.send("Ce challenge n'existe pas.") return False else: if box: if str(ctx.channel.type) == "private": await ctx.send("Tu n'as pas oublié quelque chose ?") else: box_name = ctx.channel.name.lower() box_status = htbot.check_box(box_name) if box_status: status = trio_run( functools.partial(htbot.work_on, box_name, ctx.author.id, box=True)) if not status: print("Erreur.") return False elif status == "success": await ctx.send("Bonne chance {} ! ❤".format( ctx.author.mention)) return True elif status == "already_owned": await ctx.send("Tu as déjà terminé cette box !") return True else: await ctx.send("Tu n'as pas oublié quelque chose ?") elif chall: await ctx.send("Tu n'as pas oublié quelque chose ?")
async def check_host_vip(self): trio_run(htbot.check_if_host_is_vip)
async def htb_login(self): trio_run(htbot.login)