Beispiel #1
0
async def is_roles_channel(ctx):
    server_info = Discord.select().where(
        Discord.server_id == str(ctx.guild.id))
    if len(server_info) == 0:
        return False
    return str(ctx.channel.id) == Discord.select().where(
        Discord.server_id == str(ctx.guild.id))[0].roles_channel_id
Beispiel #2
0
 async def PullNewLog(self, ctx):
     """This will pull the latest log from warcraft logs if there is one to pull"""
     discord_server = Discord.select().where(
         Discord.server_id == str(ctx.guild.id))
     if len(discord_server) == 0:
         await ctx.channel.send(
             "You have not run the setup commands for this server. Please do that first."
         )
         return
     logs = await self.__class__.check_for_logs(str(ctx.guild.id))
     channel = ctx.guild.get_channel(
         int(discord_server[0].logs_report_channel_id))
     async with ctx.channel.typing():
         if type(logs) is str:
             await channel.send(logs)
         elif type(logs) is list:
             for x in logs:
                 e = discord.Embed(title=x['title'],
                                   colour=discord.Colour.purple())
                 e.add_field(name='Zone',
                             value=botoptions.zones.get(
                                 x['zone'], 'Unknown Zone'))
                 e.url = "https://www.warcraftlogs.com/reports/" + x['id']
                 e.timestamp = datetime.datetime.fromtimestamp(x['start'] /
                                                               1e3)
                 e.set_thumbnail(
                     url=botoptions.zone_pictures.get(x['zone']))
                 e.set_image(
                     url=
                     "https://s3.amazonaws.com/file3.guildlaunch.net/462275/tabard.png"
                 )
                 await channel.send(embed=e)
Beispiel #3
0
 async def auto_pull_log(self, server_id):
     """This is the same as the above command but is used for the task that checks every 5 minutes."""
     discord_server = Discord.select().where(Discord.server_id == server_id)
     if len(discord_server) == 0:
         return
     if discord_server[0].guild is None:
         return
     if discord_server[0].logs_report_channel_id is None:
         return
     logs = await self.__class__.check_for_logs(server_id)
     channel = self.bot.get_guild(int(server_id)).get_channel(
         int(discord_server[0].logs_report_channel_id))
     if not logs:
         return
     elif type(logs) == str:
         return
     else:
         for x in logs:
             e = discord.Embed(title=x['title'],
                               colour=discord.Colour.purple())
             e.add_field(name='Zone',
                         value=botoptions.zones.get(x['zone'],
                                                    'Unknown Zone'))
             e.url = "https://www.warcraftlogs.com/reports/" + x['id']
             e.timestamp = datetime.datetime.fromtimestamp(x['start'] / 1e3)
             e.set_thumbnail(url=botoptions.zone_pictures.get(
                 x['zone'],
                 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/d9/Icon-round-Question_mark.svg/1024px-Icon-round-Question_mark.svg.png'
             ))
             e.set_image(
                 url=
                 "https://s3.amazonaws.com/file3.guildlaunch.net/462275/tabard.png"
             )
             await channel.send(embed=e)
Beispiel #4
0
    async def SetupGuild(self, ctx):
        discord_server = Discord.select().where(
            Discord.server_id == str(ctx.guild.id))
        if len(discord_server) == 0:
            await ctx.channel.send(
                "You have not setup your discord settings. Please do that first then come back to this command."
            )
            return
        guild_dict = {
            "name": "",
            "display_name": "",
            "server": "",
            "region": ""
        }

        def check(message):
            return message.author == ctx.author and str(
                message.channel) == f"Direct Message with {ctx.author}"

        def process_response(message, field):
            if field == "name":
                guild_dict['name'] = message.lower()
                guild_dict['display_name'] = message
            else:
                guild_dict[field] = message

        try:
            await ctx.author.send(
                "To setup the guild settings you need 3 things.\n"
                "Your guild's name, your guild's server, and your guild's region. Be sure to have this "
                "information before starting this process.")
            await ctx.author.send("Please enter your guild's name.")
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "name")
            await ctx.author.send("Please enter your guild's server.")
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "server")
            await ctx.author.send("Please enter your guild's region.")
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "region")
            discord_server[0].guild = Guild.create(**guild_dict)
            discord_server[0].save()
            await ctx.author.send(
                "All information stored! Your guild is now linked to your discord server!"
            )
        except asyncio.TimeoutError:  # This fires if the user doesn't respond in 20 seconds
            await ctx.channel.send(
                "Oops! You ran out of time! Call the command again when you're ready!"
            )
Beispiel #5
0
 async def post_new_article(self, server_id):
     discord_server = Discord.select().where(Discord.server_id == server_id)
     if len(discord_server) == 0:
         return
     if discord_server[0].wowhead_channel_id is None:
         return
     articles = await self.grab_new_articles()
     channel = self.bot.get_guild(int(server_id)).get_channel(
         int(discord_server[0].wowhead_channel_id))
     for x in articles:
         e = discord.Embed(title=x.title, colour=discord.Colour.purple())
         e.add_field(name='Summary', value=self.create_summary(x.summary))
         e.url = x.link
         e.timestamp = datetime.strptime(x.published, '%a, %d %b %Y %X %z')
         e.set_thumbnail(
             url='https://wow.zamimg.com/images/logos/wh-logo.png')
         await channel.send(embed=e)
Beispiel #6
0
 async def check_for_logs(server_id):
     """This checks the WarcraftLogs site for new logs"""
     logs = []
     server = Discord.select().where(Discord.server_id == server_id)
     if server[0].guild is None:
         return "There is no guild associated with this discord server."
     params = {
         'api_key': config.warcraftLogsAPI
     }  # Needed to access the WarcraftLogs api
     url = f"https://www.warcraftlogs.com:443/v1/reports/guild/{server[0].guild.name}/{server[0].guild.server}/{server[0].guild.region}?"  # This is the URL to pull logs
     async with aiohttp.ClientSession() as session:  # Start a new session
         async with session.get(url,
                                params=params) as resp:  # Get the response
             log_info = await resp.json()  # Store json information
             await asyncio.sleep(0.250)  # Wait to close
             await session.close()  # Close
     if type(log_info) is dict:
         if log_info['status'] == 400:
             return log_info['error']
     for log in log_info:
         date = datetime.datetime.fromtimestamp(log['start'] / 1e3)
         date = datetime.datetime.strftime(date, '%Y-%m-%d')
         log_exists = ''
         try:
             log_exists = Logs.get_or_create(
                 log_id=log['id'],
                 log_date=date,
                 log_title=log['title'],
                 log_zone=log['zone'],
                 guild=Guild.get(Guild.name == server[0].guild.name))
         except peewee.IntegrityError:
             continue
         if log_exists[1] is False:
             continue
         else:
             logs.append(log)
     if len(logs) == 0:
         return "No new logs available"
     if len(logs) > 5:
         return logs.clear()
     return logs
Beispiel #7
0
    async def RequestRole(self, ctx):
        """This command is used to request a discord role on the server
        The bot will prompt you for your character name and the realm you're character is on.
        They must be typed in that order with a space in between and spelled correctly.
        example: ExampleCharacter maiev
        """
        server_info = Discord.select().where(
            Discord.server_id == str(ctx.guild.id))
        guild_info = server_info[0].guild
        await ctx.channel.send(
            "Whoa! Looks like you're requesting a role on discord!")
        await ctx.channel.send(
            "Put your character name and realm(In that order, separated by a space) exactly as "
            "they are spelled and I'll double check my records!")

        def check(
            message
        ):  # This check is used to ensure it's the same user and channel who sent the first message
            return message.author == ctx.author and ctx.channel == message.channel

        try:
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            character = response.content.split()
            if len(character) < 2:
                await ctx.channel.send(
                    "Oops! You didn't enter the information correctly!")
                return
            response = await Roles.check_character(character[0], character[1])
            if response.get('status') is not None:
                if response['reason'] == 'Realm not found.':
                    await ctx.channel.send(
                        "Looks like you entered the realm name incorrectly! Double "
                        "check and try again!")
                elif response['reason'] == 'Character not found.':
                    await ctx.channel.send(
                        "Unfortunately I couldn't find a character with that name! Double check "
                        "you spelled it correctly and try again!")
            elif response.get('guild') is None:
                await ctx.channel.send(
                    "Looks like you aren't in the guild yet or your character hasn't updated."
                    "Try logging completely out of the game and trying again!")
            elif guild_info.display_name in response['guild']['name']:
                await ctx.channel.send("Assigning roles!")
                roles = ctx.guild.roles
                server_roles = server_info[0].roles_assign
                roles_to_add = []
                for role in roles:
                    if role.name in server_roles:
                        roles_to_add.append(role)
                for role in roles_to_add:
                    await ctx.author.add_roles(
                        role, reason="Bot added requested roles.", atomic=True)
                await self.bot.get_guild(ctx.guild.id).get_channel(
                    int(server_info[0].roles_report_channel_id)
                ).send(
                    f"{ctx.author.name} requested and was granted these roles {server_roles}"
                )

            elif response['guild']['name'] != guild_info.display_name:
                await ctx.channel.send(
                    "Looks like you aren't in the guild yet or your character hasn't updated."
                    "Try logging completely out of the game and trying again!")

            # Run a check to see what guild the character is in here.
        except asyncio.TimeoutError:  # This fires if the user doesn't respond in 20 seconds
            await ctx.channel.send(
                "Oops! You ran out of time! Call the command again when you're ready!"
            )
Beispiel #8
0
async def is_dung_chan(ctx):
    """Used to check if the command was called from the correct channel in the guild discord"""
    server_info = Discord.select().where(Discord.server_id == str(ctx.guild.id))
    if len(server_info) == 0:
        return False
    return str(ctx.channel.id) == Discord.select().where(Discord.server_id == str(ctx.guild.id))[0].mythic_plus_report_channel
Beispiel #9
0
    async def GetStats(self, ctx, realm, region, char_name):
        """Pull your raiderio stats from the website
        realm: The realm your character is on
        region: The region your realm is in
        char_name: The name of your character
        """
        channel = self.bot.get_guild(ctx.guild.id).get_channel(int(Discord.select().where(Discord.server_id == str(ctx.guild.id))[0].mythic_plus_report_channel))
        async with ctx.channel.typing():
            stats = await self.__class__.PullIOStats(realm=realm, char_name=char_name, region=region)
            # This data is pulled from the http request, see https://raider.io/api#!/character/get_api_v1_characters_profile for more details
            e = discord.Embed(title='RaiderIO Mythic+ Stats', colour=discord.Colour.blue())
            ranks = stats[1]
            scores = stats[2]
            stats = stats[0]
            e.url = stats['profile_url']
            e.set_thumbnail(url=stats['thumbnail_url'])

            e.add_field(name="Character", value='Name: ' + stats['name'] + '\n' +
                        'Race: ' + stats['race'] + '\n' +
                        'Class: ' + stats['class'] + '\n' +
                        'Spec: ' + stats['active_spec_name'] + '\n' +
                        'Faction: ' + stats['faction'])

            e.add_field(name="Score", value="All: " + str(scores['all'])+'\n'+
                        'DPS: '+str(scores['dps'])+'\n'+
                        'Healer: '+str(scores['healer'])+'\n'+
                        'Tank: '+str(scores['tank']))

            e.add_field(name='All Classes and Roles', value='World: ' + str(ranks['overall']['world']) + '\n' +
                        'Region: ' + str(ranks['overall']['region']) + '\n' +
                        'Realm: ' + str(ranks['overall']['realm']))

            if ranks['dps']['world'] > 0:
                e.add_field(name='All DPS', value='World: ' + str(ranks['dps']['world']) + '\n' +
                            'Region: ' + str(ranks['dps']['region']) + '\n' +
                            'Realm: ' + str(ranks['dps']['realm']))

            if ranks['healer']['world'] > 0:
                e.add_field(name='All Healers', value='World: ' + str(ranks['healer']['world']) + '\n' +
                            'Region: ' + str(ranks['healer']['region']) + '\n' +
                            'Realm: ' + str(ranks['healer']['realm']))

            if ranks['tank']['world'] > 0:
                e.add_field(name='All Tanks', value='World: ' + str(ranks['tank']['world']) + '\n' +
                            'Region: ' + str(ranks['tank']['region']) + '\n' +
                            'Realm: ' + str(ranks['tank']['realm']))

            e.add_field(name=stats['class']+' All Roles', value='World: '+str(ranks['class']['world'])+'\n'+
                        'Region: '+str(ranks['class']['region'])+'\n'+
                        'Realm: '+str(ranks['class']['realm']))

            if ranks['class_dps']['world'] > 0:
                e.add_field(name='All '+stats['class']+' DPS', value='World: '+str(ranks['class_dps']['world'])+'\n'+
                            'Region: ' + str(ranks['class_dps']['region']) + '\n' +
                            'Realm: ' + str(ranks['class_dps']['realm']))

            if ranks['class_healer']['world'] > 0:
                e.add_field(name='All '+stats['class']+' Healers', value='World: '+str(ranks['class_healer']['world'])+'\n'+
                            'Region: ' + str(ranks['class_healer']['region']) + '\n' +
                            'Realm: ' + str(ranks['class_healer']['realm']))

            if ranks['class_tank']['world'] > 0:
                e.add_field(name='All '+stats['class']+' Tanks', value='World: '+str(ranks['class_tank']['world'])+'\n'+
                            'Region: ' + str(ranks['class_tank']['region']) + '\n' +
                            'Realm: ' + str(ranks['class_tank']['realm']))

            e.set_footer(text="Date Retrieved: " + str(datetime.datetime.now()))

            await channel.send(ctx.message.author.mention)
            await channel.send(embed=e)
Beispiel #10
0
    async def SetupDiscord(self, ctx):
        server_id = str(ctx.guild.id)
        discord_dict = {
            "server_id": server_id,
            "welcome_channel_id": None,
            "roles_channel_id": None,
            "roles_report_channel_id": None,
            "logs_report_channel_id": None,
            "mythic_plus_report_channel": None,
            "wowhead_channel_id": None,
            "roles_assign": None,
            "guild": None
        }

        def check(message):
            return message.author == ctx.author and str(
                message.channel) == f"Direct Message with {ctx.author}"

        def process_response(message, field):
            if message == "skip":
                return
            else:
                if field == "roles_assign":
                    message = message.split(',')
                    discord_dict[field] = message
                else:
                    discord_dict[field] = message

        try:
            await ctx.author.send(
                "To set up the bot, you're gonna need to enable developer mode on discord!\n"
                "To learn how to do that, go to the website {Link Here} and follow the step by step guide."
            )
            await ctx.author.send(
                "We'll now go step by step to setup the bot! If there is any option you don't want to\n"
                "enable just type 'skip' to skip that step!")
            await ctx.author.send(
                "Please enter the Welcome channel ID. This is the channel where you would welcome new\n"
                "users to your discord server.")
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "welcome_channel_id")
            await ctx.author.send(
                "Please enter the Roles channel ID. This is the channel where you would have new guild\n"
                "members request discord roles.")
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "roles_channel_id")
            await ctx.author.send(
                "Please enter the Roles admin channel ID. This is where the bot will log all roles "
                "requests.\nThis is required if you enabled the Roles channel."
            )
            # wait for id
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "roles_report_channel_id")
            await ctx.author.send(
                "Please enter all the roles you would like to assign to new members. The roles must\n"
                "be entered exactly as they are spelled on Discord. Separate them using a comma.\n"
                "Example: Test Role, Another Role, And Another Role")
            # wait for text
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "roles_assign")
            await ctx.author.send(
                "Please enter the Logs channel ID. This is the channel where all your warcraft logs\n"
                "will be reported. WarcraftLogs is the only site currently supported."
            )
            # wait for id
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "logs_report_channel_id")
            await ctx.author.send(
                "Please enter the Mythic Plus channel ID. This is where your mythic plus raiderio scores\n"
                "will be reported.")
            # wait for id
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "mythic_plus_report_channel")
            await ctx.author.send(
                "Please enter the Wowhead News channel ID. This is where news articles from Wowhead\n"
                "will be posted.")
            # wait for id
            response = await self.bot.wait_for(
                'message', check=check,
                timeout=20.0)  # Wait for the response, 20 seconds max
            process_response(response.content, "wowhead_channel_id")
            Discord.create(**discord_dict)
            await ctx.author.send(
                "All done storing the information! You can setup your guild settings now!"
            )
        except asyncio.TimeoutError:  # This fires if the user doesn't respond in 20 seconds
            await ctx.channel.send(
                "Oops! You ran out of time! Call the command again when you're ready!"
            )