예제 #1
0
    async def remove_team(self,
                          ctx: Context,
                          category: Optional[CategoryChannel] = None):
        """deletes a category with the channels inside"""
        if category is None:
            await ctx.channel.send(
                f"Bitte gebe einen richtigen Teamnamen an!\n"
                f"Achte auf Großschreibung\n"
                f"Nutzung: `{PREFIX}remove_team [dein team name]` (in \" \" wenn er Leerzeichen hat)"
            )
            return

        # Admins had to join a Team to delete it
        '''
        users = User.get_users(id=ctx.author.id)
        user = users[0] if len(users) else [None]*7
        if user[6] != category.name:
            embed: Embed = Embed(color=0x5865F2, title="Fehler")
            embed.add_field(name="Nicht in Team",
                            value=f"Melde dich in einem DM-Channel mit `{self.bot.user}` mit `{PREFIX}anmelden` an")
            await ctx.channel.send(embed=embed)
            return
        '''

        if not ctx.guild.get_member(
                ctx.author.id).guild_permissions.manage_roles:
            await ctx.channel.send("Du hast nicht genug perms!")
            return

        if not DbUser.get_users(team=category.name):
            await ctx.channel.send("Hey! Warum willst du das löschen?\n"
                                   "Das ist gar kein Team... \\:(")
            return

        for user in DbUser.get_users(team=category.name):
            DbUser.delete_user(id=user[0])

        await self.ext.delete_team(self.bot, category)
예제 #2
0
    async def validates(self, reaction: Reaction, user: User):
        """inserts the user into the DB, if `YES` was reacted"""

        # if the bot has added the reaction
        if user == self.bot.user:
            return

        # if the reaction was made on a server
        if not isinstance(reaction.message.channel, DMChannel):
            return

        # if a invalid reaction was added
        if reaction.emoji not in (YES, NO):
            return

        # if there is no embed on the message
        if len(reaction.message.embeds) != 1:
            return

        # if the user cancels the check in
        if reaction.emoji == NO:
            await reaction.message.delete()
            return

        embed: Embed = reaction.message.embeds[0]

        if embed.title == TITLE_NEW:
            attrs = {}
            for field in embed.fields:
                attrs[field.name] = field.value

            user_data = {
                "id": user.id,
                "user": user.name,
                "mail": attrs.get(EMAIL),
                "name": attrs.get(NAME),
                "school": attrs.get(SCHOOL),
                "cl4ss": attrs.get(CLASS),
                "team": attrs.get(TEAM)
            }
            DbUser.new_user(**user_data)
            print(Fg.MAGENTA + f"Added new user to the DB! {user_data}" +
                  Style.RESET_ALL)

            member: Member = self.bot.guilds[0].get_member(user.id)

            role: Role = await Ext.create_team(self.bot, user_data["team"],
                                               member)
            await member.add_roles(role)
            await user.send(
                f"Du wurdest dem Team `{user_data['team']}` hinzugefügt!")

            await reaction.message.delete()
            return

        if embed.title == TITLE_DEL:
            users = DbUser.get_users(id=user.id)
            if not len(users):
                return
            user_ = users[0]

            DbUser.delete_user(id=user.id)
            print(Fg.MAGENTA + f"Removed user {user} from the DB!" +
                  Style.RESET_ALL)

            role: Role = get(self.bot.guilds[0].roles, name=user_[6])
            await self.bot.guilds[0].get_member(user.id).remove_roles(role)
            await user.send(
                "Du hast dich soeben abgemeldet.\n"
                "Ich wünsche dir noch einen schönen Tag oder Abend oder was auch immer \\:)"
            )

            if not DbUser.get_users(team=role.name):
                await Ext.delete_team(
                    self.bot, get(self.bot.guilds[0].categories,
                                  name=role.name))
                await user.send(
                    "Das Team wurde automatisch gelöscht, da es keine Mitglieder mehr hatte!"
                )

            await reaction.message.delete()
            return