Ejemplo n.º 1
0
async def update(member, dm, data, skipUpdatedMessage = False):
    """Updates the user's roles."""

    cmdResult = ""

    level = data["level"] - 1
    sub = data["subscribed"]

    # Special case: Contributors.
    if level == 997:
        if not has_role(member, id_contrib):
            await remove_rank_roles(member)
            await add_role(member, id_contrib)
            cmdResult += s_verify["contrib_add"] + "\n"

    if level != 997 and has_role(member, id_contrib):
        await remove_contrib_role(member)
        cmdResult += s_verify["contrib_remove"] + "\n"

    # Special case: Bug Hunter
    if level == 999:
        if not has_role(member, id_bughunter):
            await remove_rank_roles(member)
            await add_role(member, id_bughunter)
            cmdResult += s_verify["bughunter_add"] + "\n"

    if level != 999 and has_role(member, id_bughunter):
        await remove_bughunter_role(member)
        cmdResult += s_verify["bughunter_remove"] + "\n"

    # Normal ranks.
    if level < len(id_ranks):
        if not has_role(member, id_ranks[level]):
            await remove_rank_roles(member)
            await add_role(member, id_ranks[level])

            cmdResult += s_verify["level_updated"] + "\n"
        elif not skipUpdatedMessage:
                cmdResult += s_verify["level_up-to-date"] + "\n"

    # Checks for the users' sub status.
    if sub == 0:
        if has_role(member, id_sub):
            await remove_sub_role(member)
            cmdResult += s_verify["sub_remove"] + "\n"
    else:
        if not has_role(member, id_sub):
            await add_role(member, id_sub)
            cmdResult += s_verify["sub_added"] + "\n"

    # Checks if the users has the verified role.
    if not has_role(member, id_verified):
        await add_role(member, id_verified)
        cmdResult += s_verify["verified_added"] + "\n"

    if cmdResult != "":
        try:
            await dm.send(cmdResult)
        except:
            print("\t{} has blocked DMs.".format(member))
Ejemplo n.º 2
0
    async def remove_token(self, ctx, member: discord.Member):

        if has_role(ctx.author, id_admin) or has_role(ctx.author, id_mod):
            # Removes the user from the DB.
            database.remove_user_by_discord_uid(db, member.id)
            msg = s_verify_del["done"].format(member.id)
            
            # Removes the user's roles (verified, sub, contrib, rank..)
            await remove_verified_role(member)
            await remove_sub_role(member)
            await remove_rank_roles(member)
            await remove_contrib_role(member)

            await ctx.send(msg)
Ejemplo n.º 3
0
    async def role_botdev(self, ctx, member: discord.Member):
        devRole = ctx.guild.get_role(id_dev)

        # Check if the user has the requiered role to issue the command. (DEV LEAD)
        if has_role(ctx.author, id_devLead):

            # Then toggles the role for the target user.
            if not has_role(member, id_dev):
                await member.add_roles(devRole)
                await ctx.send(s_devrole["welcome"].format(member.mention))
            else:
                await member.remove_roles(devRole)
                await ctx.send(s_devrole["leave"].format(member.mention))
        else:
            await ctx.send(s_no_perm)
Ejemplo n.º 4
0
    async def role_announce(self, ctx):
        announceRole = ctx.guild.get_role(id_announcerole)

        user = ctx.author

        # Then toggles the role for the target user.
        if not has_role(user, id_announcerole):
            await user.add_roles(announceRole)
            await ctx.send(s_announcementrole["on"].format(user.mention))
        else:
            await user.remove_roles(announceRole)
            await ctx.send(s_announcementrole["off"].format(user.mention))
Ejemplo n.º 5
0
    async def votecancel(self, ctx):
        if has_role(ctx.author, id_admin):
            vote_id = clear_file()

            if vote_id is not None:
                chan_announcement = self.bot.get_channel(id_announcements)
                vote_msg = (await chan_announcement.fetch_message(vote_id))
                await vote_msg.delete()

                await ctx.send(s_vote["canceled"])
            else:
                await ctx.send(s_vote["nothing_to_cancel"])
Ejemplo n.º 6
0
    async def giveaway_cancel(self, ctx):
        if has_role(ctx.author, id_admin):
            giveaway_id = clear_file()

            if giveaway_id != None:
                chan_announcement = self.bot.get_channel(id_announcements)
                giveaway_msg = (await
                                chan_announcement.fetch_message(giveaway_id))
                await giveaway_msg.delete()

                await ctx.send(s_giveaway["canceled"])
            else:
                await ctx.send(s_giveaway["nothing_to_cancel"])
Ejemplo n.º 7
0
    async def room(self, ctx):
        if not has_role(ctx.author, id_admin):
            botMsg = await ctx.send(s_no_perm)

            await asyncio.sleep(5)

            await botMsg.delete()
            await ctx.message.delete()
            return

        # Gets channel.
        channel = self.bot.get_channel(id_channel)

        # Getting the API's JSON.
        data = await api_fetch(c_api_url["newrooms"])

        await announce_room(channel, data[0])
Ejemplo n.º 8
0
    async def new_room(self, ctx, room):
        if not has_role(ctx.author, adminID):
            botMsg = await ctx.send(s_no_perm)

            await asyncio.sleep(5)

            await botMsg.delete()
            await ctx.message.delete()
            return

        data = await api_fetch(c_api_url["room"], "/", room)

        if data["success"] == False:
            await ctx.send(s_room["code_not_found"].format(room))
            return

        channel = self.bot.get_channel(channelID)

        await announce_room(channel, data, room)
Ejemplo n.º 9
0
async def remove_rank_roles(member):
    """Remove the member's rank/level roles."""

    for rId in id_ranks:
        if has_role(member, rId):
            await member.remove_roles(get(member.guild.roles, id=rId))
Ejemplo n.º 10
0
    async def giveaway(self, ctx):

        gDesc = ""
        gReac = None
        gTimeHour = 0

        # Remove the command.
        await ctx.message.delete()

        # Check for the user to be admin.
        if not has_role(ctx.author, id_admin):
            botMsg = await ctx.send(s_no_perm)
            await asyncio.sleep(5)
            await botMsg.delete()
            return

        # Check for the author.
        def checkAuth(m):
            return m.author == ctx.author

        def checkDone(m):
            return (m.author == ctx.author
                    and m.content.lower() == s_giveaway["confirm_word"])

        botMsgCancel = await ctx.send(s_giveaway["cancel"])

        # Retrieve the giveaway's description.
        botMsg = await ctx.send(s_giveaway["desc"])
        gDescMsg = await self.bot.wait_for('message', check=checkAuth)
        gDesc = gDescMsg.content

        await botMsg.delete()
        await gDescMsg.delete()

        if gDescMsg.content.lower() == s_giveaway["cancel_word"]:
            await botMsgCancel.delete()
            confirmDelMsg = await ctx.send(s_giveaway["canceled"])
            await asyncio.sleep(5)
            await confirmDelMsg.delete()
            return

        # Getting the reaction to enter the giveaway.
        botMsgText = s_giveaway["reaction"]
        botMsg = await ctx.send(botMsgText)

        # Waits for the reaction and DONE message.
        isDone = False
        while not isDone:
            msg = await self.bot.wait_for('message', check=checkAuth)

            if msg.content.lower() == s_giveaway["cancel"]:
                await botMsgCancel.delete()
                await botMsg.delete()
                await msg.delete()
                confirmDelMsg = await ctx.send(s_giveaway["canceled"])
                await asyncio.sleep(5)
                await confirmDelMsg.delete()
                return

            # Checks if the amount of emojis matches the amount of options.
            # We need to re-cache the message to retrieve the reactions.
            cacheBotMsg = await ctx.channel.fetch_message(botMsg.id)

            if len(cacheBotMsg.reactions) != 1:
                await msg.delete()
                errorMsg = await ctx.send(s_giveaway["reaction_limit"])
                await asyncio.sleep(5)
                await errorMsg.delete()
            else:
                isDone = True
                reaction = cacheBotMsg.reactions[0]

        # Asigns reaction.
        gReac = reaction.emoji

        # Clears msg.
        await botMsg.delete()
        await msg.delete()

        # Gets the time the giveaway should last.
        isDone = False
        while (not isDone):
            timeAsk = await ctx.send(s_giveaway["time"])
            msg = await self.bot.wait_for('message', check=checkAuth)

            if msg.content.lower() == s_giveaway["cancel_word"]:
                await botMsgCancel.delete()
                await msg.delete()
                await timeAsk.delete()

                confirmDelMsg = await ctx.send(s_giveaway["canceled"])
                await asyncio.sleep(5)
                await confirmDelMsg.delete()
                return

            try:
                gTimeHour = int(msg.content)
                isDone = True
            except:
                errorMsg = await ctx.send(s_giveaway["time_int_only"])
                await asyncio.sleep(2)
                await errorMsg.delete()

                isDone = False
            finally:
                await timeAsk.delete()
        await msg.delete()

        # Confirmation embed.
        embed = officialEmbed(
            s_giveaway["confirm_title"],
            gDesc,
            footer=s_giveaway["confirm_footer"].format(gTimeHour))
        embed.add_field(name=s_giveaway["confirm_reaction"], value=gReac)

        # Sends embed.
        botEmbed = await ctx.send(embed=embed)

        # Asks for validation.
        botMsg = await ctx.send(s_giveaway["confirm_text"])
        giveawayValid = await self.bot.wait_for('message', check=checkAuth)

        # Checks validation's answer.
        if not giveawayValid.content.lower() == "yes":
            cancelMsg = await ctx.send(s_giveaway["canceled"])

            # Removes useless msg.
            await botMsgCancel.delete()
            await botEmbed.delete()
            await botMsg.delete()
            await giveawayValid.delete()
            await cancelMsg.delete()
        else:
            # Removes useless msg.
            await botMsgCancel.delete()
            await botMsg.delete()
            await giveawayValid.delete()

            # Makes embed.
            embed = officialEmbed("Giveaway", gDesc)
            embed.add_field(name=s_giveaway["announce_reaction"], value=gReac)

            # Sends the giveaway.
            chan_announcement = self.bot.get_channel(id_announcements)
            gEmbed = await chan_announcement.send(embed=embed)

            # Adds the reactions to it.
            await gEmbed.add_reaction(gReac)

            # Saves it in the persistence file.
            endingTime = (
                datetime.now() +
                timedelta(hours=gTimeHour)).strftime('%Y-%m-%dT%H:%M:%S.%f')
            data = {
                "desc": gDesc,
                "ending_time": endingTime,
                "message_id": gEmbed.id
            }

            with open(file_persistence, 'w') as outfile:
                json.dump(data, outfile)

            # Waits and fetches results.
            await self.giveaway_output(data)
Ejemplo n.º 11
0
    async def vote(self, ctx):
        vDesc = ""
        vOpt = []
        vReac = []
        vTimeHour = 0

        # Remove the command.
        await ctx.message.delete()

        # Check for the user to be admin.
        if not has_role(ctx.author, id_admin):
            botMsg = await ctx.send(config.get_string("commands")["no_perm"])
            await asyncio.sleep(5)
            await botMsg.delete()
            return

        # Check for the author.
        def checkAuth(m):
            return m.author == ctx.author

        def checkDone(m):
            return (m.author == ctx.author and m.content.lower() == "done")

        botMsgCancel = await ctx.send(s_vote["cancel_message"])

        # Retrieve the vote's description.
        botMsg = await ctx.send(s_vote["vote_desc"])
        vDescMsg = await self.bot.wait_for('message', check=checkAuth)
        vDesc = vDescMsg.content

        await botMsg.delete()
        await vDescMsg.delete()

        if vDescMsg.content.lower() == "cancel":
            await botMsgCancel.delete()
            confirmDelMsg = await ctx.send(s_vote["canceled"])
            await asyncio.sleep(5)
            await confirmDelMsg.delete()
            return

        # Retrieve the vote's options and reactions.
        botMsg = await ctx.send(s_vote["vote_options"])

        isDone = False
        optMsg = []

        # Gettings all options.
        while not isDone:
            msg = await self.bot.wait_for('message', check=checkAuth)
            if msg.content.lower() == "done":
                isDone = True
            elif msg.content.lower() == "cancel":
                await botMsgCancel.delete()
                await botMsg.delete()
                await msg.delete()
                for m in optMsg:
                    await m.delete()

                confirmDelMsg = await ctx.send(s_vote["canceled"])
                await asyncio.sleep(5)
                await confirmDelMsg.delete()
                return
            else:
                vOpt.append(msg.content)
            optMsg.append(msg)

        # Clearing the messages.
        await botMsg.delete()
        for m in optMsg:
            await m.delete()

        # Doing the same but for reactions.
        botMsgText = s_vote["vote_reactions"]
        for i in range(0, len(vOpt)):
            botMsgText += ("\n" + str(i + 1) + ". - " + vOpt[i])
        botMsg = await ctx.send(botMsgText)

        # Waits for the DONE message.
        isDone = False
        while not isDone:
            msg = await self.bot.wait_for('message', check=checkAuth)

            if msg.content.lower() == "cancel":
                await botMsgCancel.delete()
                await botMsg.delete()
                await msg.delete()
                confirmDelMsg = await ctx.send(s_vote["canceled"])
                await asyncio.sleep(5)
                await confirmDelMsg.delete()
                return

            # Checks if the amount of emojis matches the amount of options.
            cacheBotMsg = await ctx.channel.fetch_message(botMsg.id)

            if len(cacheBotMsg.reactions) != len(vOpt):
                await msg.delete()
                errorMsg = await ctx.send(s_vote["reactions_amount_wrong"])
                await asyncio.sleep(5)
                await errorMsg.delete()
            else:
                isDone = True

        # Sets the emojis.
        for r in cacheBotMsg.reactions:
            vReac.append(r.emoji)

        # Clears msg.
        await botMsg.delete()
        await msg.delete()

        # Gets the time the vote should last.
        isDone = False
        while (not isDone):
            timeAsk = await ctx.send(s_vote["vote_time"])
            msg = await self.bot.wait_for('message', check=checkAuth)

            if msg.content.lower() == "cancel":
                await botMsgCancel.delete()
                await msg.delete()
                await timeAsk.delete()
                confirmDelMsg = await ctx.send(s_vote["canceled"])
                await asyncio.sleep(5)
                await confirmDelMsg.delete()
                return

            try:
                vTimeHour = int(msg.content)
                isDone = True
            except:
                errorMsg = await ctx.send(s_vote["time_int_only"])
                await asyncio.sleep(2)
                await errorMsg.delete()
                isDone = False
            finally:
                await timeAsk.delete()
        await msg.delete()

        # Confirmation embed.
        embed = officialEmbed(title=s_vote["recap"],
                              desc=vDesc,
                              footer=s_vote["recap_time"].format(vTimeHour))
        for i in range(0, len(vOpt)):
            embed.add_field(name=vReac[i], value=vOpt[i])

        # Sends embed.
        botEmbed = await ctx.send(embed=embed)

        # Asks for validation.
        botMsg = await ctx.send(s_vote["confirm"])
        voteValid = await self.bot.wait_for('message', check=checkAuth)

        # Checks validation's answer.
        if not voteValid.content.lower() == "yes":
            cancelMsg = await ctx.send(s_vote["canceled"])

            # Removes useless msg.
            await botMsgCancel.delete()
            await botEmbed.delete()
            await botMsg.delete()
            await voteValid.delete()
            await cancelMsg.delete()
        else:
            # Removes useless msg.
            await botMsgCancel.delete()
            await botMsg.delete()
            await voteValid.delete()

            # Makes embed.
            embed = officialEmbed("Vote", vDesc)
            for i in range(0, len(vOpt)):
                embed.add_field(name=vReac[i], value=vOpt[i])

            # Sends the vote.
            chan_announcement = self.bot.get_channel(id_announcements)
            vEmbed = await chan_announcement.send(embed=embed)
            # Adds the reactions to it.
            for i in range(0, len(vReac)):
                await vEmbed.add_reaction(vReac[i])

            # Saves it in the persistence file.
            endingTime = (
                datetime.now() +
                timedelta(hours=vTimeHour)).strftime('%Y-%m-%dT%H:%M:%S.%f')
            data = {
                "desc": vDesc,
                "options": vOpt,
                "ending_time": endingTime,
                "message_id": vEmbed.id
            }

            with open(file_persistence, 'w') as outfile:
                json.dump(data, outfile)

            # Waits and fetches results.
            await self.vote_output(data)
Ejemplo n.º 12
0
    async def issue(self, ctx):

        # Remove the command.
        await ctx.message.delete()

        # Check for the user to be admin.
        if not (has_role(ctx.author, id_admin) or has_role(ctx.author, id_mod)):
            botMsg = await ctx.send(s_no_perm)
            time.sleep(5)
            await botMsg.delete()
            return

        # Check for the author.
        def check(m):
            return m.author == ctx.author

        # Retrieve the issue's name.
        botMsg = await ctx.send(s_jira["issue_name"])
        issueNameMsg = await self.bot.wait_for('message', check=check)
        issueName = issueNameMsg.content

        await botMsg.delete()
        await issueNameMsg.delete()

        # Retrieve the issue's desc.
        botMsg = await ctx.send(s_jira["issue_desc"])

        issueDescMsg = await self.bot.wait_for('message', check=check)
        issueDesc = issueDescMsg.content + "\n -- Created by: " + ctx.author.display_name

        await botMsg.delete()
        await issueDescMsg.delete()

        # Confirmation embed.
        embed = officialEmbed(
            "New issue", s_jira["confirm_title"])

        embed.add_field(name="Name", value=issueName)
        embed.add_field(name="Description", value=issueDesc)

        # Sends embed.
        botEmbed = await ctx.send(embed=embed)

        # Asks for validation.
        botMsg = await ctx.send(s_jira["confirm"])
        issueValid = await self.bot.wait_for('message', check=check)

        # Checks validation's answer.
        if issueValid.content.lower() == "yes":
            # Removes useless msg.
            await botMsg.delete()
            await issueValid.delete()

            # Creates the issue on JIRA.
            # The payload made out of the issue's vars.
            payload = json.dumps({
                "fields": {
                    "summary": issueName,
                    "issuetype": {
                        "id": issueType
                    },
                    "project": {
                        "key": issueProject
                    },
                    "description": {
                        "type": "doc",
                        "version": 1,
                        "content": [
                            {
                                "type": "paragraph",
                                "content": [
                                    {
                                        "text": issueDesc,
                                        "type": "text"
                                    }
                                ]
                            }
                        ]
                    }
                }
            })

            # Sends the the POST request.
            response = requests.request(
                "POST",
                issueUrl,
                data=payload,
                headers=headers,
                auth=auth
            )
            print("### JIRA issue creation report:")
            print(issueName + " : " + issueDesc)
            print(json.dumps(json.loads(response.text),
                             sort_keys=True, indent=4, separators=(",", ": ")) + "\n")

            # Notifies the user.
            await ctx.send(s_jira["confirmation"].format(ctx.author.mention))
        else:
            # Removes useless msg.
            await botEmbed.delete()
            await botMsg.delete()
            await issueValid.delete()

            # Removes cancel msg.
            botMsg = await ctx.send(s_jira["canceled"])
            time.sleep(5)
            await botMsg.delete()