async def addRole(context, value): server = Server(context.guild.id) a = Tools.got_the_role(server.admin, context.author) if (server.admin["roles"] != [] or server.admin["users"] != []) and not Tools.got_the_role( server.admin, context.author): await Tools.SendError(context.channel, server.GetLanguage().NoPrivileges) else: embed = Embed.BasicEmbed(color=discord.Colour.orange()) added_roles = str() already_added_roles = str() added_user = str() already_added_user = str() if value == "teacher": roles = server.teacher elif value == "admin": roles = server.admin for role in context.message.role_mentions: if role.id not in roles["roles"]: roles["roles"].append(role.id) added_roles += role.mention + "\n" else: already_added_roles += role.mention + "\n" for user in context.message.mentions: if user.id not in roles["users"]: roles["users"].append(user.id) added_user += user.mention + "\n" else: already_added_user += user.mention + "\n" if added_roles == "" and already_added_roles == "" and added_user == "" and already_added_user == "": await Tools.SendError( context.channel, "You need to add roles or users to use the command") else: if added_roles != "": embed.add_field(name="Added roles", value=added_roles) if already_added_roles != "": embed.add_field(name="Roles already added", value=already_added_roles) if added_user != "": embed.add_field(name="Added users", value=added_user) if already_added_user != "": embed.add_field(name="Users already added", value=already_added_user) server.Save_Settings() await Tools.AdminCommand(context, embed, "Add teacher Command")
async def CheckReaction(self, reaction: discord.Reaction, user, entry: str): reactionContent = str(reaction).strip(" ") if reactionContent == "✅": # si l'utilisateur a coché présent if Tools.got_the_role( self.callList[entry].classroom, user): # si user a le role de la classe correspondante await self.callList[entry].AddStudent( user) # on le rajoute à la liste d'appel elif not Tools.got_the_role( readGuild(reaction.message.guild.id)['botID'], user): await reaction.message.remove_reaction("✅", user) await Tools.embedError( user, "You do not have the right to click on ✅, you're not part of this class!" ) elif reactionContent in ("🆗", "🛑"): # Check if user got teacher privileges if self.callList[entry].teacher == user: await reaction.message.clear_reactions() if reactionContent == "🆗": await reaction.message.channel.send( "<@{}> :{} <@&{}>".format( user.id, returnLanguage( readGuild( reaction.message.guild.id)["language"], "FinishCall"), self.callList[entry].classroom)) await self.finishCall(reaction.message.channel, entry, reaction.message.guild.id, reaction) else: await reaction.message.channel.send( returnLanguage( readGuild(reaction.message.guild.id)["language"], "cancelCall")) del self.callList[entry] elif not Tools.got_the_role( readGuild(reaction.message.guild.id)['botID'], user): # pas le bot await reaction.message.remove_reaction(reactionContent, user) await Tools.embedError( user, "You can't stop the call, you do not have teacher privileges!" ) else: # other emoji await reaction.message.remove_reaction(reactionContent, user) await Tools.embedError( user, "Do not use another emoji on this message while the call is not finished!" )
async def predicate(context): data = Server(context.guild.id) if Tools.got_the_role(data.admin, context.author): return True await Tools.SendError(context.channel, data.returnLanguage("NoPrivileges")) return False
async def reset(context): data = readGuild(context.guild.id) if Tools.got_the_role( data["admin"], context.author ) or context.message.author == context.guild.owner: data["admin"] = [] data["teacher"] = [] data["language"] = "en" data["prefix"] = ".Check " data["sysMessages"] = True data["mp"] = True data["ShowPresents"] = True data["delay"] = 10 editGuild(context.guild.id, data) embed = discord.Embed( color=discord.Colour.orange(), title= "**__Factory reset:__**\nLanguage set to English\nAdmins and teachers list " "reseted\n**Prefix :** `.Check`\n**Show presents students, Sys Messages and " "Private Messages :** Activated\nDelay for for late students after a call : " "10 minutes") embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) await Admin.AdminCommand(context, embed) else: await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges"))
async def Delay(context, delay: str): data = readGuild(context.guild.id) if Tools.got_the_role(data["admin"], context.author): embed = discord.Embed(color=discord.Color.red()) embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) try: delay = int(delay) if delay < 0: raise ValueError data["delay"] = delay embed.title = f"New delay : **{delay} minutes**" editGuild(context.guild.id, data) except ValueError: embed.title = "This is not a positive number\n Enter 0 if you do not want to have any delay" await Admin.AdminCommand(context, embed) else: await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges"))
async def predicate(context): data = Server(context.guild.id) if Tools.got_the_role(data.teacher, context.author): return True await Tools.SendError(context.channel, data.returnLanguage("notTeacher")) return False
async def prefix(context, arg): data = readGuild(context.guild.id) if Tools.got_the_role(data["admin"], context.author): try: set_prefix(context.guild.id, arg) embed = discord.Embed( color=discord.Colour.orange(), title=returnLanguage( readGuild(context.guild.id)["language"], "newPrefix") + f"**{arg}**", description="You still can use \"`.Check `\"") embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) await Admin.AdminCommand(context, embed) except discord.ext.commands.errors.MissingRequiredArgument: await Tools.embedError(context.channel, "You did not specify a prefix") else: await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges"))
async def ShowPresents(context): """ Activate/Deactivate Show presents students in call summary """ data = readGuild(context.guild.id) if Tools.got_the_role(data["admin"], context.author): if data["showPresents"]: data["showPresents"] = False embed = discord.Embed( color=discord.Color.red(), title="Call summary will only show absents students") else: data["showPresents"] = True embed = discord.Embed( color=discord.Color.red(), title="Call summary will show absents and presents students" ) embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) editGuild(context.guild.id, data) await Admin.AdminCommand(context, embed) else: await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges"))
async def DeactivateMP(context): data = readGuild(context.guild.id) if Tools.got_the_role(data["admin"], context.author): if data["mp"]: data["mp"] = False embed = discord.Embed( color=discord.Color.red(), title="Private messages are now disabled") else: data["mp"] = True embed = discord.Embed( color=discord.Color.red(), title="Private messages are now activated") embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) editGuild(context.guild.id, data) await Admin.AdminCommand(context, embed) else: await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges"))
async def language(context, lang=None): if lang in ["fr", "en", "de"]: data = readGuild(context.guild.id) if Tools.got_the_role(data["admin"], context.author): data["language"] = lang embed = discord.Embed(color=discord.Colour.orange(), title=returnLanguage( lang, "changeLanguage")) embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) await Admin.AdminCommand(context, embed) editGuild(context.guild.id, data) else: await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges")) else: await Tools.embedError( context.channel, "Unknown language:\n**Languages :**\n• English: en\n• French: fr\n• German: de" )
async def Call(self, context, classroom, showAll: bool): class_role = Tools.convert(classroom) data = readGuild(context.guild.id) if class_role is None: await Tools.embedError("This is not a role, but a specific user") else: if Tools.got_the_role(data["teacher"], context.author): self.callList[ f"{context.guild.id}-{context.message.id}"] = Check( class_role, context.message.author, showAll, data["delay"] if data["delay"] > 0 else 0) message = returnLanguage(data["language"], "startcall") embed = discord.Embed(color=discord.Colour.green(), title=message[0], description=message[1]) embed.set_author(name=Tools.name(context.message.author), icon_url=context.message.author.avatar_url) embed.add_field(name=f"**__{message[2]}__**", value=classroom) embed.add_field(name="Date", value=date.today().strftime("%d/%m/%Y")) embed.set_footer(text=message[3]) await context.channel.send(embed=embed) await context.message.add_reaction( "✅") # on rajoute les réactions ✅ & 🆗 await context.message.add_reaction("🆗") await context.message.add_reaction("🛑") else: await context.channel.send("<@{}> : {}".format( context.author.id, returnLanguage(data["language"], "notTeacher")))
async def AddStudents(self, reactions: list): for react in reactions: if str(react.emoji) == "✅": self.listStudents = [ user for user in await react.users().flatten() if Tools.got_the_role(self.role, user) ] break
async def AddStudents(self, context, messageID): msg = await context.fetch_message(messageID) for react in msg.reactions: if str(react.emoji) == "✅": self.listStudents = [ user for user in await react.users().flatten() if Tools.got_the_role(self.role, user) ] break
async def rmRole(context, value, args): guild = str(context.guild.id) data = readGuild(guild) if not data["admin"]: await Tools.embedError( context.channel, returnLanguage(data["language"], "zeroPrivileges")) elif Tools.got_the_role(data["admin"], context.author): embed = discord.Embed(color=discord.Colour.orange()) embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) removed_roles = "" not_removed_roles = "" for i in args: role = Tools.convert(i) if role in data[value]: removed_roles += i + "\n" data[value].remove(role) else: not_removed_roles += i + "\n" if removed_roles == "" and not_removed_roles == "": embed.add_field( name="You need to write role(s) to use the command", value=f"{value} rm @role") await context.channel.send(embed=embed) else: if removed_roles != "": embed.add_field(name="Removed roles", value=removed_roles) if not_removed_roles != "": embed.add_field(name=f"Was not an {value}", value=not_removed_roles) editGuild(guild, data) await Admin.AdminCommand(context, embed, "Remove Command") else: await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges"))
async def addRole(context, value, args): guild = str(context.guild.id) data = readGuild(guild) if data["admin"] != [] and not Tools.got_the_role( data["admin"], context.author): await Tools.embedError( context.channel, returnLanguage(data["language"], "NoPrivileges")) else: embed = discord.Embed(color=discord.Colour.orange()) embed.set_author( name="CheckStudents", url="https://github.com/Renaud-Dov/CheckStudents", icon_url= "https://raw.githubusercontent.com/Renaud-Dov/CheckStudents/master/img/logo.png" ) added_roles = "" already_added_roles = "" for i in args: role = Tools.convert(i) if role not in data[value]: data[value].append(role) added_roles += i + "\n" else: already_added_roles += i + "\n" if added_roles == "" and already_added_roles == "": embed.add_field( name="You need to add roles to use the command", value=f"{value} add @role1 @role2") await context.channel.send(embed=embed) else: if added_roles != "": embed.add_field(name="Added roles", value=added_roles) if already_added_roles != "": embed.add_field(name="Already added", value=already_added_roles) editGuild(guild, data) await Admin.AdminCommand(context, embed, "Add teacher Command")
async def Reset(self, context): data = Server(context.guild.id) if not Tools.got_the_role( data.admin, context.author ) and context.message.author != context.guild.owner: await Tools.SendError(context.channel, data.GetLanguage().NoPrivileges) return None data.Reset() data.Save_Settings() embed = Embed.BasicEmbed( color=discord.Colour.orange(), title= "**__Factory reset:__**\nLanguage set to English\nAdmins and teachers list " "reseted\n**Prefix :** `.Check`\n**Show presents students, Sys Messages and " "Private Messages :** Activated\nDelay for for late students after a call : " "10 minutes") await Tools.AdminCommand(context, embed)
async def predicate(context): data = Server(context.guild.id) if Tools.got_the_role(data.teacher, context.author): return True await Tools.SendError(context.channel, data.GetLanguage().NoPrivileges) return False