def __init__(self, xe): if 'taxidList' in xe.attrib: fn = os.path.join(SyncDB.DOWNLOAD_DIR(),'syncdb_species.pickle') if os.path.isfile(fn): syncdb_species = MyUtils.load(fn) SyncDB.ROOT_SPECIES = syncdb_species['ROOT_SPECIES'] SyncDB.SUPPORTED_SPECIES = syncdb_species['SUPPORTED_SPECIES'] SyncDB.PARENT_SPECIE_MAP = syncdb_species['PARENT_SPECIE_MAP'] SyncDB.SPECIE_SUBTREE = syncdb_species['SPECIE_SUBTREE'] else: self.buid_sp_tree() SyncDB.ROOT_SPECIES = filter(None, [x for x in xe.attrib['taxidList'].split(',')]) SyncDB.SUPPORTED_SPECIES = [] SyncDB.PARENT_SPECIE_MAP = {} SyncDB.SPECIE_SUBTREE = {} for s in SyncDB.ROOT_SPECIES: st=self.get_specie_subtree(int(s)) print "Taxonomy subtree for %s : [%s]"%(s, ','.join(st)) SyncDB.SPECIE_SUBTREE[s] = []; for t in st: SyncDB.PARENT_SPECIE_MAP[t] = s SyncDB.SPECIE_SUBTREE[s].append(t); SyncDB.SUPPORTED_SPECIES += st syncdb_species = {'ROOT_SPECIES': SyncDB.ROOT_SPECIES,'SUPPORTED_SPECIES':SyncDB.SUPPORTED_SPECIES,'PARENT_SPECIE_MAP':SyncDB.PARENT_SPECIE_MAP,'SPECIE_SUBTREE':SyncDB.SPECIE_SUBTREE} MyUtils.dump_object(syncdb_species,'syncdb_species',SyncDB.DOWNLOAD_DIR()) else: print "taxidList is missing in DefaultSpecies tag" exit(-1)
async def shufle(self, ctx, number=6): if MyUtils(ctx.guild).G4check(ctx): await self.bot.change_presence(activity=discord.Game( name="Attribu des lobby")) category = MyUtils(ctx.guild).getVendrediChillCategory() lobbyChan = category.voice_channels lobbyChan.pop(0) print(lobbyChan) random.shuffle(lobbyChan) generalChanID = discord.utils.get(category.voice_channels, name="General").id for memberID in [ i for i in self.bot.get_channel( generalChanID).voice_states.keys() ]: member = await ctx.guild.fetch_member(memberID) try: while True: randomLobby = lobbyChan[random.randint( 0, len(lobbyChan) - 1)] print(randomLobby) if len(randomLobby.members) == number: print("pop") lobbyChan.pop(lobbyChan.index(randomLobby)) else: break await member.move_to(randomLobby) except ValueError: await ctx.send("Woups... Quelque chose c'est mal passé") else: raise discord.ext.commands.CheckFailure
async def hideChannel(self, ctx): if MyUtils(ctx.guild).G4check(ctx): await self.bot.change_presence(activity=discord.Game( name="Désinstalle le vendredi chill")) categoty = MyUtils(ctx.guild).getVendrediChillCategory() for channels in categoty.channels: await channels.delete() await categoty.delete() else: raise discord.ext.commands.CheckFailure
async def HelpCommand(ctx, embedMessage): if MyUtils(ctx.guild).G4check(ctx): await ctx.send(embed=embedMessage) else: await ctx.send( "Je ne peux pas te donner de l'aide sur cette commande, tu ne peux pas l'utiliser" )
async def unload(ctx, name=None): if name and MyUtils(ctx.guild).getAdminRole() in ctx.message.author.roles: try: bot.unload_extension(name) await ctx.send(name + " unload") except: await ctx.send(name + " has has already down") else: raise discord.ext.commands.CheckFailure
async def stopLan(self, ctx): utils = MyUtils(ctx.guild) async def deleteCategory(cat): for channels in cat.channels: await channels.delete() await cat.delete() if MyUtils(ctx.guild).G4check(ctx): await self.bot.change_presence(activity=discord.Game(name="Désinstalle la LAN")) games = ["Orga LAN", "Viewers", "League of Legends", "Rocket League", "CS:GO", "Minecraft", "AOE2"] categories = [utils.getLanOneCategory(name) for name in games] group = asyncio.gather(*[deleteCategory(category)for category in categories]) loop = asyncio.get_event_loop() loop.run_until_complete(group) loop.close() else: raise discord.ext.commands.CheckFailure
async def showChannel(self, ctx, number=15): if MyUtils(ctx.guild).G4check(ctx): await self.bot.change_presence(activity=discord.Game( name="Prepare le vendredi chill")) category = await ctx.guild.create_category("🎉Vendredi Chill🎉" ) await ctx.guild.create_text_channel(f"General", category=category) await ctx.guild.create_voice_channel(f"General", category=category) for i in range(number): await ctx.guild.create_voice_channel(f"lobby-{i + 1}", category=category) else: raise discord.ext.commands.CheckFailure
async def startLan(self, ctx, number=15): if MyUtils(ctx.guild).G4check(ctx): await self.bot.change_presence(activity=discord.Game(name="Prepare la LAN")) # Categorie orga orga = await ctx.guild.create_category("Orga LAN") await ctx.guild.create_text_channel(f"General", category=orga) await ctx.guild.create_voice_channel(f"General", category=orga) await ctx.guild.create_voice_channel(f"Commentateurs / Streamer", category=orga) # Categorie pour le Viewers viewers = await ctx.guild.create_category("Viewers") await ctx.guild.create_text_channel(f"Annonce", category=viewers) for i in range(5): await ctx.guild.create_voice_channel(f"lobby-{i + 1}", category=viewers) # Cetegorie pour les joueurs group = await asyncio.gather( # LoL Category(ctx, "League of Legends", teams=True), # Rocket League Category(ctx, "Rocket League", teams=True), # CSGO Category(ctx, "CS:GO", teams=True), # Minecraft Category(ctx, "Minecraft"), # AoE2 Category(ctx, "AOE2") ) loop = asyncio.get_event_loop() loop.run_until_complete(group) loop.close() else: raise discord.ext.commands.CheckFailure
async def help(self, ctx, subject=""): subject = subject.lower() await self.bot.change_presence(activity=discord.Game(name="Help")) if MyUtils(ctx.guild).G4check(ctx) and subject == "": await ctx.send(embed=embed.g4helpEmbed) elif (MyUtils(ctx.guild).G4check(ctx) and subject == "nog4help") \ or (subject == ""): await ctx.send(embed=embed.helpEmbed) elif subject != "": if subject == "ssh": await ctx.send(embed=embed.sshEmbed) elif subject == "rdp": await ctx.send(embed=embed.rdpEmbed) elif subject == "vpn": await ctx.send(embed=embed.vpnEmbed) elif subject in ["terminal", "cli", "ilc"]: await ctx.send(embed=embed.terminalEmbed) elif subject in ["git", "github"]: await ctx.send( "Git / GitHub : \n" "Voici de l'aide sur TChelp : \n" "https://github.com/TCastus/TChelp/blob/master/Git_GitHub" "/Presentation.md") elif subject == "tsa": await ctx.send( "TSA... :sweat_smile: \n" "Je suis vraiment désolé mais je suis dans l'incapacité de te " "donner de l'aide sur ce sujet :no_mouth:") elif subject == "passation": await HelpCommand(ctx, embed.helpPassationEmbed) elif subject == "newyear": await HelpCommand(ctx, embed.helpNewyearEmbed) elif subject == "vendredichill": await HelpCommand(ctx, embed.helpVendrediChill) elif subject in ["invitation", "lien"]: await ctx.send(embed=embed.helpInvitationEmbed) elif subject in ["video", "metier", "futur"]: await ctx.send(embed=embed.helpvideoEmbed) elif subject in ["ipinfo", "ipi"]: await ctx.send(embed=embed.helpIpInfo) elif subject in ["nslookup", "dns_lookup"]: await ctx.send(embed=embed.helpDns_lookup) elif subject == "soa_lookup": await ctx.send(embed=embed.helpSoa_lookup) elif subject in ["calendar", "cal", "calendrier" ] + ["tomorrow", "demain", "dem", "tom"]: await ctx.send(embed=embed.helpCalendar) elif subject in ["tgg", "thomas", "ginny"]: await ctx.send(embed=embed.helpTgg) elif subject == "starling": await ctx.send(embed=embed.helpStarling) elif subject == "gns3": await ctx.send(embed=embed.helpGNS3) else: await ctx.send( "Désolé, je ne sais pas te donner de l'aide sur ce sujet... \n " "Peut-être que tu trouveras une réponse sur le repo " "[TChelp](https://github.com/TCastus/TChelp) :wink: ")
async def passation(self, ctx): await self.bot.change_presence(activity=discord.Game( name="Do passation")) if self.passationStatus > 0: await ctx.send("Passation déjà en cours ... ") return # Creation du role oldG4 = await ctx.guild.create_role( name= f"G4 {datetime.datetime.now().year - 1}-{datetime.datetime.now().year}", permissions=discord.Permissions(1333259863), colour=discord.Colour(2123412)) # attributions des roles au channels await MyUtils(ctx.guild).getG4TxtChannel().set_permissions( oldG4, overwrite=perms.g4TxtPerms) await MyUtils(ctx.guild).getG4VocalChannel().set_permissions( oldG4, overwrite=perms.g4VocalPerms) await MyUtils(ctx.guild).getPassationTxtChannel().set_permissions( oldG4, overwrite=perms.g4TxtPerms) await MyUtils(ctx.guild).getPassationVocalChannel().set_permissions( oldG4, overwrite=perms.g4VocalPerms) await ctx.send( "Je cherche les anciens membres de l'ASTUS, patiente un moment...") for member in ctx.guild.members: if MyUtils(ctx.guild).getG4Role() in member.roles: await member.remove_roles(MyUtils(ctx.guild).getG4Role()) await member.add_roles(oldG4) if MyUtils(ctx.guild).getASTUSRole() in member.roles: await member.remove_roles(MyUtils(ctx.guild).getASTUSRole()) if MyUtils(ctx.guild).getRespCommRole() in member.roles: await member.remove_roles(MyUtils(ctx.guild).getRespCommRole()) if MyUtils(ctx.guild).getRespSiteRole() in member.roles: await member.remove_roles(MyUtils(ctx.guild).getRespSiteRole()) await member.add_roles( MyUtils(ctx.guild).getAncienRespSiteRole()) if MyUtils(ctx.guild).getRespTeamEntrepriseRole() in member.roles: await member.remove_roles( MyUtils(ctx.guild).getRespTeamEntrepriseRole()) if MyUtils(ctx.guild).getRespTeamEventRole() in member.roles: await member.remove_roles( MyUtils(ctx.guild).getRespTeamEventRole()) if MyUtils(ctx.guild).getAncienRespSiteRole() in member.roles: await member.remove_roles( MyUtils(ctx.guild).getAncienRespSiteRole()) if MyUtils(ctx.guild).getTeamEventRole() in member.roles: await member.remove_roles( MyUtils(ctx.guild).getTeamEventRole()) if MyUtils(ctx.guild).getTeamEntrepriseRole() in member.roles: await member.remove_roles( MyUtils(ctx.guild).getTeamEntrepriseRole()) self.passationStatus += 1 await ctx.send( "Les anciens membres de l'ASTUS ne font plus partis de l'ASTUS") await ctx.send("Qui sont les nouveaux membres du G4 ? ") def checkMessage(message): return message.author == ctx.message.author and ctx.message.channel == message.channel while self.passationStatus > 0: try: if self.passationStatus == 1: newG4 = await self.bot.wait_for("message", check=checkMessage) members = newG4.content.split(" ") if len(members) != 4: await ctx.send("Le G4 doit être composé de 4 membres") else: await MyUtils(ctx.guild).newAstus( members, MyUtils(ctx.guild).getASTUSRole(), MyUtils(ctx.guild).getG4Role()) await ctx.send( "Qui sont les membres de la team Event ?") self.passationStatus += 1 if self.passationStatus == 2: newTeamEvent = await self.bot.wait_for("message", check=checkMessage) members = newTeamEvent.content.split(" ") if len(members) != 3: await ctx.send( "La team event doit être composée de 3 membres \n" "Le responsable te sera demandé juste aprés") else: await MyUtils(ctx.guild).newAstus( members, MyUtils(ctx.guild).getASTUSRole(), MyUtils(ctx.guild).getTeamEventRole()) await ctx.send("Qui est le resp de la team Event ?") self.passationStatus += 1 if self.passationStatus == 3: newRespTeamEvent = await self.bot.wait_for( "message", check=checkMessage) members = newRespTeamEvent.content.split(" ") if len(members) != 1: await ctx.send( "Il n'y a qu'un responsable de la team event") else: await MyUtils(ctx.guild).newAstus( members, MyUtils(ctx.guild).getASTUSRole(), MyUtils(ctx.guild).getRespTeamEventRole()) await ctx.send( "Qui sont les membres de la team Entreprise ?") self.passationStatus += 1 if self.passationStatus == 4: newTeamEntreprise = await self.bot.wait_for( "message", check=checkMessage) members = newTeamEntreprise.content.split(" ") if len(members) != 3: await ctx.send( "La team Entreprise doit être composée de 3 membres \n" "Le responsable te sera demandé juste apres") else: await MyUtils(ctx.guild).newAstus( members, MyUtils(ctx.guild).getASTUSRole(), MyUtils(ctx.guild).getTeamEntrepriseRole()) await ctx.send( "Qui est le resp de la team Entreprise ?") self.passationStatus += 1 if self.passationStatus == 5: newRespTeamEntreprise = await self.bot.wait_for( "message", check=checkMessage) members = newRespTeamEntreprise.content.split(" ") if len(members) != 1: await ctx.send( "Il n'y a qu'un responsable de la team Entreprise") else: await MyUtils(ctx.guild).newAstus( members, MyUtils(ctx.guild).getASTUSRole(), MyUtils(ctx.guild).getRespTeamEntrepriseRole()) await ctx.send("Qui est le resp site international ?") self.passationStatus += 1 if self.passationStatus == 6: newRespSite = await self.bot.wait_for("message", check=checkMessage) members = newRespSite.content.split(" ") if len(members) != 1: await ctx.send("Il n'y a qu'un responsable du site") else: await MyUtils(ctx.guild).newAstus( members, MyUtils(ctx.guild).getASTUSRole(), MyUtils(ctx.guild).getRespSiteRole()) await ctx.send("Qui est le resp comm ?") self.passationStatus += 1 if self.passationStatus == 7: newRespComm = await self.bot.wait_for("message", check=checkMessage) members = newRespComm.content.split(" ") if len(members) != 1: await ctx.send("Il n'y a qu'un responsable comm") else: await MyUtils(ctx.guild).newAstus( members, MyUtils(ctx.guild).getASTUSRole(), MyUtils(ctx.guild).getRespCommRole()) await ctx.send("Tape ``end`` pour finir") self.passationStatus += 1 if self.passationStatus == 8: end = await self.bot.wait_for("message", check=checkMessage) if end.content == "end": self.passationStatus = 0 await ctx.send("Passation finie !") await MyUtils(ctx.guild).getG4TxtChannel().send( "@here vous devez : \n" "- Mettre jour le portail VA \n" "- Prendre RDV à la banque \n" "- Changer les membres de l'asso sur le portail" " du service public \n" "- demander les MDP a l'ancien bureau") else: await ctx.send( "Tu dois taper ``end`` pour finir la passation") except Exception: await ctx.send("Une erreur est survenue...") await ctx.send( "Content d'avoir été à tes côtés pendant ton mandat :wink:")
async def cog_check(self, ctx): return MyUtils(ctx.guild).getG4Role() in ctx.message.author.roles
async def on_raw_reaction_add(payload): messageID = payload.message_id if messageID == 726611125252128768: await bot.change_presence(activity=discord.Game(name="Give some roles") ) guildID = payload.guild_id guild = discord.utils.find(lambda g: g.id == guildID, bot.guilds) if payload.emoji.name == '3️⃣': # print("3TC") await payload.member.add_roles( MyUtils(guild).get3TCRole(), MyUtils(guild).getStudentRole()) elif payload.emoji.name == '4️⃣': # print("4TC") await payload.member.add_roles( MyUtils(guild).get4TCRole(), MyUtils(guild).getStudentRole()) elif payload.emoji.name == '5️⃣': # print("5TC") await payload.member.add_roles( MyUtils(guild).get5TCRole(), MyUtils(guild).getStudentRole()) elif payload.emoji.name == '🇦': # print("TCA") await payload.member.add_roles(MyUtils(guild).getTCARole()) elif payload.emoji.name == '👨🏫': # print("Prof") await payload.member.add_roles(MyUtils(guild).getProfRole()) elif payload.emoji.name == '🎓': # print("Diplomes") await payload.member.add_roles(MyUtils(guild).getDiplomesRole()) elif payload.emoji.name == '🆕': # print("Futur TC") await payload.member.add_roles(MyUtils(guild).getFuturTCRole()) elif payload.emoji.name == "💼": await payload.member.add_roles(MyUtils(guild).getEntrepriseRole())
def setUp(self): self.driver = webdriver.Firefox() self.base_url = "https://mpower.tvo.org/educators/#/signup/" self.driver.get(self.base_url) self.myutils = MyUtils(self.driver)
class mytests(unittest.TestCase): @classmethod def setUp(self): self.driver = webdriver.Firefox() self.base_url = "https://mpower.tvo.org/educators/#/signup/" self.driver.get(self.base_url) self.myutils = MyUtils(self.driver) #TC 1 : To verify the registration page elements , input parameters are passed for properties.py def test_registration_page_validation(self): self.myutils.log('Test 1 : Registration page validation') if self.myutils.chk_registration_page(): if self.myutils.chk_registration_page_elements(): self.myutils.log( 'Test 1 : Registration page validation - Test Passed') return True self.myutils.log('Test 1 : Registration page validation - Test Failed') return False #TC 2 : To verify the registration page with valid inputs , input parameters are passed for properties.py def test_account_registration(self): self.myutils.log('Test 2 : Test new account registration') if self.myutils.do_new_registration(): self.myutils.log( 'Test 2 : Test new account registration - Test Passed') return True self.myutils.log( 'Test 2 : Test new account registration - Test Failed') return False #TC 3 : To verify the registration cancel and check navigation to home page upon cancel def test_account_registration_cancel(self): self.myutils.log('Test 3 : Test new account registration cancellation') if self.myutils.do_new_registration_cancel(): self.myutils.log( 'Test 3 : Test new account registration cancellation - Test Passed' ) return True self.myutils.log( 'Test 3 : Test new account registration cancellation - Test Failed' ) return False #TC 4 : To verify the mandatory fileds in the registration page def test_mandatoryfield_validation(self): self.myutils.log('Test 4 : Test new account registration') if self.myutils.chk_mandate_field_reg_form(): self.myutils.log( 'Test 4 : Test new account registration - Test Passed') return True self.myutils.log( 'Test 4 : Test new account registration - Test Failed') return False #TC 5 : To verify the registration by adding new school def test_add_new_school(self): self.myutils.log('Test 5 : Test registration with new school name') if self.myutils.registration_new_school(): self.myutils.log( 'Test 5 : Test registration with new school name - Test Passed' ) return True self.myutils.log( 'Test 5 : Test registration with new school name - Test Failed') return False #TC 6 : To verify the registration page with invalid email id def test_registeration_invalid_emailid(self): self.myutils.log('Test 6 : Test registration with invalid emailid') if self.myutils.registration_invalid_emailid(): self.myutils.log( 'Test 6 : Test registration with invalid emailid - Test Passed' ) return True self.myutils.log( 'Test 6 : Test registration with invalid emailid - Test Failed') return False #TC 7 : To validate the name filed. test data and messages are read from an csv file def test_field_validation(self): self.myutils.log('Test 7 : Name Filed validation') if self.myutils.check_field_validation_from_csv(): self.myutils.log('Test 7 : Name Filed validation - Test Passed') return True self.myutils.log('Test 7 : Name Filed validation - Test Failed') return False #TC 8 : Test to check the error message when the role limit exceeds. pre-req is to have atleast three administrator # roles for a board/school def test_role_limit_exceeds(self): self.myutils.log( 'Test 8 : Test to check the error message when the role limit exceeds' ) if self.myutils.registration_limit_exceeded(): self.myutils.log( 'Test 8 : Test to check the error message when the role limit exceeds - Test Passed' ) return True self.myutils.log( 'Test 8 : Test to check the error message when the role limit exceeds - Test Failed' ) return False #TC 9 : Test to check the duplicate account reisteration.I assume that untill we validate the email #post registeration we will be able register a account with same details #used APIs for creating a account in the backend def test_duplicate_account_creation(self): self.myutils.log( 'Test 9 : Test to check the duplicate account creation') if self.myutils.check_duplicate_account_creation(): self.myutils.log( 'Test 9 : Test to check the duplicate account creation - Test Passed' ) return True self.myutils.log( 'Test 9 : Test to check the duplicate account creation - Test Failed' ) return False #TC 10 : click and check if all the legal links like terms of use, copyright.. are working properly def test_legal_links(self): self.myutils.log('Test 10 : Test for legal links') if self.myutils.check_all_legal_links(): self.myutils.log('Test 10 : Test for legal links - Test Passed') return True self.myutils.log('Test 10 : Test for legal links - Test Failed') return False def tearDown(self): self.driver.close()
async def newyear(self, ctx): await self.bot.change_presence(activity=discord.Game(name="Upgrade roles")) for member in ctx.guild.members: if MyUtils(ctx.guild).getFuturTCRole() in member.roles: await member.remove_roles(MyUtils(ctx.guild).getFuturTCRole()) await member.add_roles(MyUtils(ctx.guild).get3TCRole()) await member.add_roles(MyUtils(ctx.guild).getStudentRole()) elif MyUtils(ctx.guild).get3TCRole() in member.roles: await member.remove_roles(MyUtils(ctx.guild).get3TCRole()) await member.add_roles(MyUtils(ctx.guild).get4TCRole()) elif MyUtils(ctx.guild).get4TCRole() in member.roles: await member.remove_roles(MyUtils(ctx.guild).get4TCRole()) await member.add_roles(MyUtils(ctx.guild).get5TCRole()) elif MyUtils(ctx.guild).get5TCRole() in member.roles: await member.remove_roles(MyUtils(ctx.guild).get5TCRole(), MyUtils(ctx.guild).getStudentRole()) await member.add_roles(MyUtils(ctx.guild).getDiplomesRole()) await ctx.send("Changement des rôles :) : \n " " - les Futurs TC sont maintenant des 3TC \n" " - les 3TC sont maintenant des 4TC \n" " - les 4TC sont maintenant des 5TC \n" " - les 5TC sont maintenant des Diplômés \n" )