Exemplo n.º 1
0
    async def botstats(self, ctx):
        """Displays some bot statistics"""

        await ctx.send(
            "Due to scaling issues with my stats, I'm disabling use of this command for now. Going to rework the way it works, and enable it after thats done"
        )
        return

        embed = discord.Embed(color=discord.Color.green())

        embed.set_author(name=self.bot.user.name,
                         icon_url=self.bot.user.avatar_url)

        embed.add_field(name="Servers/Guilds",
                        value="{:,}".format(len(self.bot.guilds)))
        embed.add_field(name="Registered Users",
                        value="{:,}".format(
                            len(
                                list(
                                    filter(lambda user: user.steam,
                                           botdata.userinfo_list())))))

        commands = loggingdb_session.query(
            loggingdb.Message).filter(loggingdb.Message.command != None)
        commands_weekly = commands.filter(
            loggingdb.Message.timestamp > datetime.datetime.utcnow() -
            datetime.timedelta(weeks=1))
        embed.add_field(name="Commands", value=f"{commands.count():,}")
        embed.add_field(name="Commands (This Week)",
                        value=f"{commands_weekly.count():,}")

        cmdpfx = self.cmdpfx(ctx)
        top_commands = loggingdb_session.query(
            loggingdb.Message.command,
            func.count(loggingdb.Message.command)).filter(
                loggingdb.Message.command != None).group_by(
                    loggingdb.Message.command).order_by(
                        func.count(loggingdb.Message.command).desc())
        if top_commands.count() >= 3:
            embed.add_field(name="Top Commands",
                            value=(f"`{cmdpfx}{top_commands[0][0]}`\n"
                                   f"`{cmdpfx}{top_commands[1][0]}`\n"
                                   f"`{cmdpfx}{top_commands[2][0]}`\n"))

        top_commands_weekly = top_commands.filter(
            loggingdb.Message.timestamp > datetime.datetime.utcnow() -
            datetime.timedelta(weeks=1))
        if top_commands_weekly.count() >= 3:
            embed.add_field(name="Top Commands (This Week)",
                            value=(f"`{cmdpfx}{top_commands_weekly[0][0]}`\n"
                                   f"`{cmdpfx}{top_commands_weekly[1][0]}`\n"
                                   f"`{cmdpfx}{top_commands_weekly[2][0]}`\n"))

        await ctx.send(embed=embed)
Exemplo n.º 2
0
    async def botstats(self, ctx):
        """Displays some bot statistics"""
        embed = discord.Embed(color=discord.Color.green())

        embed.set_author(name=self.bot.user.name,
                         icon_url=self.bot.user.avatar_url)

        embed.add_field(name="Servers/Guilds",
                        value="{:,}".format(len(self.bot.guilds)))
        embed.add_field(name="Registered Users",
                        value="{:,}".format(
                            len(
                                list(
                                    filter(lambda user: user.steam32,
                                           botdata.userinfo_list())))))

        commands = loggingdb_session.query(
            loggingdb.Message).filter(loggingdb.Message.command != None)
        commands_weekly = commands.filter(
            loggingdb.Message.timestamp > datetime.datetime.utcnow() -
            datetime.timedelta(weeks=1))
        embed.add_field(name="Commands", value=f"{commands.count():,}")
        embed.add_field(name="Commands (This Week)",
                        value=f"{commands_weekly.count():,}")

        top_commands = loggingdb_session.query(
            loggingdb.Message.command,
            func.count(loggingdb.Message.command)).filter(
                loggingdb.Message.command != None).group_by(
                    loggingdb.Message.command).order_by(
                        func.count(loggingdb.Message.command).desc())
        if top_commands.count() >= 3:
            embed.add_field(name="Top Commands",
                            value=(f"`?{top_commands[0][0]}`\n"
                                   f"`?{top_commands[1][0]}`\n"
                                   f"`?{top_commands[2][0]}`\n"))

        top_commands_weekly = top_commands.filter(
            loggingdb.Message.timestamp > datetime.datetime.utcnow() -
            datetime.timedelta(weeks=1))
        if top_commands_weekly.count() >= 3:
            embed.add_field(name="Top Commands (This Week)",
                            value=(f"`?{top_commands_weekly[0][0]}`\n"
                                   f"`?{top_commands_weekly[1][0]}`\n"
                                   f"`?{top_commands_weekly[2][0]}`\n"))

        await ctx.send(embed=embed)
Exemplo n.º 3
0
    async def check_dota_patch(self):
        print("check_dota_patch() entered")
        url = "https://www.dota2.com/patches/"
        try:
            text = await httpgetter.get(url, return_type="text")
        except HttpError as e:
            print(f"patches update failed with http {e.code} error")
            await self.send_owner(
                f"patches update failed the check with a http {e.code} error")
            return  # failed, so return
        except Exception as e:
            etype = str(type(e).__name__)
            print(f"patches update failed the check w/ exception {etype}: {e}")
            await self.send_owner(
                f"patches update failed the check w/ exception {etype}: {e}")
            return  # failed, so return
        soup = BeautifulSoup(text, "html.parser")

        print("patch parse starting")

        current_patch = soup.find(name="title").contents[0]
        old_patch = botdata["dotapatch"]

        if old_patch == current_patch:
            return  # thats the current patch, do nothing
        if current_patch.strip() == "Gameplay Update":
            return  # thats what happens when theyre tryna switch it and theyre in the process, so give it a minute and try again later
        print(f"\"{current_patch}\"")
        print(current_patch == "Gameplay Update")
        print(str(current_patch) == "Gameplay Update")
        await self.send_owner(
            f"patches update triggered: (new one is '{current_patch}', old one was '{old_patch}')"
        )
        botdata["dotapatch"] = current_patch

        def count_class_in_id(element_id, classname):
            element = soup.find(id=element_id)
            if element is None:
                return 0
            return len(
                element.find_all(lambda tag: tag.get("class") == [classname]))

        description = ""
        section_counts = OrderedDict()
        section_counts["General"] = count_class_in_id("GeneralSection",
                                                      "PatchNote")
        section_counts["Item"] = count_class_in_id("ItemsSection", "ItemName")
        section_counts["Hero"] = count_class_in_id("HeroesSection", "HeroName")
        for section in section_counts:
            count = section_counts[section]
            if count > 0:
                description += f"\n{count} {section} changes"

        image_meta_tag = soup.find(name="meta", attrs={"property": "og:image"})

        if image_meta_tag is not None:
            description = ""

        if description == "" and image_meta_tag is None:
            description = "*Couldn't parse the changes.*"

        # we can improve this embed later but for now this is what we got
        embed = discord.Embed(timestamp=datetime.datetime.utcnow())
        embed.title = current_patch
        embed.url = url
        embed.description = description
        embed.set_thumbnail(
            url=
            "https://cdn.cloudflare.steamstatic.com/apps/dota2/images/blog/play/dota_logo.png"
        )
        if image_meta_tag:
            embed.set_image(url=image_meta_tag["content"])

        messageables = []
        guildinfos = botdata.guildinfo_list()
        for guildinfo in guildinfos:
            if guildinfo.dotapatchchannel is not None:
                channel = self.bot.get_channel(guildinfo.dotapatchchannel)
                if channel is not None:
                    messageables.append(channel)
                else:
                    print(
                        f"couldn't find channel {guildinfo.dotapatchchannel} when announcing dota patches"
                    )

        userinfos = botdata.userinfo_list()
        for userinfo in userinfos:
            if userinfo.dmdotapatch:
                user = self.bot.get_user(userinfo.discord)
                if user is not None:
                    messageables.append(user)
                else:
                    print(
                        f"couldn't find user {userinfo.discord} when announcing dota patches"
                    )

        tasks = []
        for messageable in messageables:
            tasks.append(messageable.send(embed=embed))

        bundler = AsyncBundler(tasks)
        print("waiting for dota patch bundle to complete")
        await bundler.wait()
        print("dota patch bundle completed")
        await self.send_owner("__Dota Patch Sent!__\n" +
                              bundler.status_as_string())