Esempio n. 1
0
    async def latest(self, ctx: commands.Context, version=None):
        if version is None:
            version = VersionInfo.getLatest(self.BC_VERSION_LIST.keys())
        if version not in self.BC_VERSION_LIST.keys():
            await ctx.send(
                f"Sorry but `{version}` does not seem to be a valid MC version that has BuildCraft releases."
            )
        else:
            async with ctx.typing():
                latestBC = VersionInfo.getLatest(self.BC_VERSION_LIST[version])
                latestBCinfo = await self.getVersionDetails(
                    "BuildCraft", latestBC)

                info = f"Buildcraft {latestBC}:\n[Changelog](https://www.mod-buildcraft.com/pages/buildinfo/BuildCraft/changelog/{latestBC}.html) | [Blog]({latestBCinfo['blog_entry'] if 'blog_entry' in latestBCinfo else 'https://www.mod-buildcraft.com'}) | [Direct download]({latestBCinfo['downloads']['main']})"
                if version in self.BCC_VERSION_LIST.keys():
                    latestBCC = VersionInfo.getLatest(
                        self.BCC_VERSION_LIST[version])
                    latestBCCinfo = await self.getVersionDetails(
                        "BuildCraftCompat", latestBCC)
                    info = f"{info}\n\nBuildcraft Compat {latestBCC}:\n[Changelog](https://www.mod-buildcraft.com/pages/buildinfo/BuildCraftCompat/changelog/{latestBCC}.html) | [Blog]({latestBCCinfo['blog_entry'] if 'blog_entry' in latestBCCinfo else 'https://www.mod-buildcraft.com'}) | [Direct download]({latestBCCinfo['downloads']['main']})"

                embed = discord.Embed(
                    colour=discord.Colour(0x54d5ff),
                    timestamp=datetime.datetime.utcfromtimestamp(time.time()),
                    description=info)
                embed.set_author(
                    name=f"BuildCraft releases for {version}",
                    url="https://www.mod-buildcraft.com/pages/download.html",
                    icon_url="https://i.imgur.com/YKGkDDZ.png")
                await ctx.send(embed=embed)
Esempio n. 2
0
async def versionChecker(checkcog:BCVersionChecker):
    GearbotLogging.info("Started BC version checking background task")
    session:aiohttp.ClientSession = checkcog.bot.aiosession
    reply:aiohttp.ClientResponse
    lastUpdate = 0
    while checkcog.running:
        try:
            async with session.get('https://www.mod-buildcraft.com/build_info_full/last_change.txt') as reply:
                stamp = await reply.text()
                stamp = int(stamp[:-1])
                if stamp > lastUpdate:
                    GearbotLogging.info("New BC version somewhere!")
                    lastUpdate = stamp
                    checkcog.BC_VERSION_LIST = await getList(session, "BuildCraft")
                    checkcog.BCC_VERSION_LIST = await getList(session, "BuildCraftCompat")
                    highestMC = VersionInfo.getLatest(checkcog.BC_VERSION_LIST.keys())
                    latestBC = VersionInfo.getLatest(checkcog.BC_VERSION_LIST[highestMC])
                    generalID = 309218657798455298
                    channel:discord.TextChannel = checkcog.bot.get_channel(generalID)
                    if channel is not None and latestBC not in channel.topic:
                        info = await checkcog.getVersionDetails("BuildCraft", latestBC)
                        newTopic = f"General discussions about BuildCraft.\n" \
                                   f"Latest version: {latestBC}\n" \
                                   f"Full changelog and download: {info['blog_entry']}"
                        await channel.edit(topic=newTopic)
                    pass
                pass
        except CancelledError:
            pass  # bot shutdown
        except Exception as ex:
            checkcog.bot.errors = checkcog.bot.errors + 1
            GearbotLogging.error("Something went wrong in the BC version checker task")
            GearbotLogging.error(traceback.format_exc())
            embed = discord.Embed(colour=discord.Colour(0xff0000),
                                  timestamp=datetime.datetime.utcfromtimestamp(time.time()))
            embed.set_author(name="Something went wrong in the BC version checker task:")
            embed.add_field(name="Exception", value=str(ex))
            v = ""
            for line in traceback.format_exc().splitlines():
                if len(v) + len(line) >= 1024:
                    embed.add_field(name="Stacktrace", value=v)
                    v = ""
                v = f"{v}\n{line}"
            if len(v) > 0:
                embed.add_field(name="Stacktrace", value=v)
            await GearbotLogging.bot_log(embed=embed)
        for i in range(1,60):
            if checkcog.force or not checkcog.running:
                break
            await asyncio.sleep(10)

    GearbotLogging.info("BC version checking background task terminated")
Esempio n. 3
0
    async def fetch_info(self, project_name):
        session: aiohttp.ClientSession = self.bot.aiosession
        async with session.get(f"https://api.cfwidget.com/mc-mods/minecraft/{project_name}") as reply:
            if reply.status is 200:  # all good, we can parse it
                parsed = json.loads(await reply.text())
                p_type = parsed["type"]
                info = {
                    "title": parsed["title"],
                    "type": f'{parsed["game"]} {p_type[:-1] if p_type.endswith("s") else p_type}',
                    "updated": parsed["last_fetch"],
                    "categories": parsed["categories"],
                    "links": dict(),
                    "thumbnail": parsed["thumbnail"],
                    "downloads": parsed["downloads"]["total"]
                }

                for link in parsed["links"]:
                    info["links"][link["title"]] = link["href"]

                mc_versions = []
                for k, v in parsed["versions"].items():
                    if "Java" not in k:
                        mc_versions.append(k)
                sorted = VersionInfo.getSortedVersions(mc_versions)
                map = OrderedDict()
                for version in sorted:
                    mod_versions_unsorted = dict()
                    mod_versions = OrderedDict()
                    version_list = []
                    for v2 in parsed["versions"][version]:
                        mod_versions_unsorted[v2["id"]] = v2
                        version_list.append(v2["id"])

                    version_list.sort()
                    version_list.reverse()
                    for v3 in version_list:
                        mod_versions[v3] = mod_versions_unsorted[v3]

                    map[version] = mod_versions
                info["versions"] = map
                return info

            elif reply.status is 202:  # New project, wait for the api to fetch it
                GearbotLogging.info(f"Info for {project_name} not available yet, trying again in 10 seconds.")
                await asyncio.sleep(10)
                return await self.fetch_info(project_name)
            elif reply.status in (400, 404):
                return None
            elif reply.status is 500:
                GearbotLogging.error(f"Fetching info for {project_name} failed.")
                return False
            else:
                GearbotLogging.error(
                    f"Got unexpected response code ({reply.status}) when fetching info for {project_name}.")
                return None  # TODO: handle failure
Esempio n. 4
0
async def updater(cog: BCVersionChecker):
    GearbotLogging.info("Started BC version checking background task")
    session: aiohttp.ClientSession = cog.bot.aiosession
    lastUpdate = 0
    while cog.running:
        try:
            # check for a newer bc version
            async with session.get(
                    'https://www.mod-buildcraft.com/build_info_full/last_change.txt'
            ) as reply:
                stamp = await reply.text()
                stamp = int(stamp[:-1])
                if stamp > lastUpdate:
                    GearbotLogging.info("New BC version somewhere!")
                    lastUpdate = stamp
                    cog.BC_VERSION_LIST = await getList(session, "BuildCraft")
                    cog.BCC_VERSION_LIST = await getList(
                        session, "BuildCraftCompat")
                    highestMC = VersionInfo.getLatest(
                        cog.BC_VERSION_LIST.keys())
                    latestBC = VersionInfo.getLatest(
                        cog.BC_VERSION_LIST[highestMC])
                    generalID = 309218657798455298
                    channel: discord.TextChannel = cog.bot.get_channel(
                        generalID)
                    old_latest = Configuration.get_persistent_var(
                        "latest_bc", "0.0.0")
                    Configuration.set_persistent_var(
                        "latest_bc", latestBC
                    )  # save already so we don't get stuck and keep trying over and over if something goes wrong
                    if channel is not None and latestBC != old_latest:
                        GearbotLogging.info(
                            f"New BuildCraft version found: {latestBC}")
                        notify_channel = cog.bot.get_channel(
                            349517224320565258)
                        await notify_channel.send(
                            f"{Emoji.get_chat_emoji('WRENCH')} New BuildCraft version detected ({latestBC})"
                        )
                        GearbotLogging.info(
                            f"Fetching metadata for BuildCraft {latestBC}")
                        message = await notify_channel.send(
                            f"{Emoji.get_chat_emoji('REFRESH')} Fetching metadata..."
                        )
                        info = await cog.getVersionDetails(
                            "BuildCraft", latestBC)
                        GearbotLogging.info(f"Metadata acquired: {info}")
                        await message.edit(
                            content=
                            f"{Emoji.get_chat_emoji('YES')} Metadata acquired")
                        if 'blog_entry' in info:
                            message = await notify_channel.send(
                                f"{Emoji.get_chat_emoji('REFRESH')} Updating general topic..."
                            )
                            newTopic = f"General discussions about BuildCraft.\n" \
                                f"Latest version: {latestBC}\n" \
                                f"Full changelog and download: {info['blog_entry']}"
                            await channel.edit(topic=newTopic)
                            await message.edit(
                                content=
                                f"{Emoji.get_chat_emoji('YES')} Topic updated")
                        else:
                            notify_channel.send(
                                f"{Emoji.get_chat_emoji('WARNING')} No blog post data found, notifying <@180057061353193472>"
                            )

                        # message = await notify_channel.send(f"{Emoji.get_chat_emoji('REFRESH')} Uploading files to CurseForge...")
                        # code, output, errors = await Utils.execute(f'cd BuildCraft/uploader && gradle curseforge -Pnew_version="{latestBC}"')
                        # GearbotLogging.info(f"Upload to CF complete\n)------stdout------\n{output}\n------stderr------\n{errors}")
                        # if code is 0:
                        #     content = f"{Emoji.get_chat_emoji('YES')} All archives successfully uploaded"
                        #     await message.edit(content=content)
                        # else:
                        #     content = f"{Emoji.get_chat_emoji('NO')} Upload failed with code {code}, notifying <@106354106196570112>"
                        #     await notify_channel.send(content)

            # update FAQs if needed
            async with session.get(
                    'https://mod-buildcraft.com/website_src/faq.md') as reply:
                data = await reply.text()
                h = hashlib.md5(data.encode('utf-8')).hexdigest()
                old = Configuration.get_persistent_var("BCFAQ", "")
                channel = cog.bot.get_channel(361557801492938762)  # FAQs
                if channel is not None and h != old:
                    Configuration.set_persistent_var("BCFAQ", h)
                    #clean the old stuff
                    await channel.purge()

                    #send banner
                    with open("BuildCraft/FAQs.png", "rb") as file:
                        await channel.send(file=File(file, filename="FAQs.png")
                                           )
                    #send content
                    out = ""
                    parts = [
                        d.strip("#").strip() for d in data.split("##")[1:]
                    ]
                    for part in parts:
                        lines = part.splitlines()
                        content = '\n'.join(lines[1:])
                        out += f"**```{lines[0].strip()}```**{content}\n"
                    for page in Pages.paginate(out,
                                               max_chars=2048,
                                               max_lines=50):
                        embed = Embed(description=page)
                        await channel.send(embed=embed)

                pass
        except CancelledError:
            pass  # bot shutdown
        except Exception as ex:
            cog.bot.errors = cog.bot.errors + 1
            GearbotLogging.error(
                "Something went wrong in the BC version checker task")
            GearbotLogging.error(traceback.format_exc())
            embed = discord.Embed(colour=discord.Colour(0xff0000),
                                  timestamp=datetime.datetime.utcfromtimestamp(
                                      time.time()))
            embed.set_author(
                name="Something went wrong in the BC version checker task:")
            embed.add_field(name="Exception", value=str(ex))
            v = ""
            for line in traceback.format_exc().splitlines():
                if len(v) + len(line) >= 1024:
                    embed.add_field(name="Stacktrace", value=v)
                    v = ""
                v = f"{v}\n{line}"
            if len(v) > 0:
                embed.add_field(name="Stacktrace", value=v)
            await GearbotLogging.bot_log(embed=embed)
        for i in range(1, 60):
            if cog.force or not cog.running:
                break
            await asyncio.sleep(10)

    GearbotLogging.info("BC version checking background task terminated")