Beispiel #1
0
 async def block_server(self, ctx, guild: Guild):
     blocked = Configuration.get_persistent_var("server_blocklist", [])
     blocked.append(guild.id)
     Configuration.set_persistent_var("server_blocklist", blocked)
     await guild.leave()
     await MessageUtils.send_to(ctx, "YES", f"{Utils.escape_markdown(guild.name)} (``{guild.id}``) has been added to the blocked servers list", translate=False)
     await GearbotLogging.bot_log(
         f"{Utils.escape_markdown(guild.name)} (``{guild.id}``) has been added to the blocked server list by {Utils.clean_user(ctx.author)}")
Beispiel #2
0
 async def block_user(self, ctx, user:DiscordUser):
     for guild in self.bot.guilds:
         if guild.owner is not None and guild.owner.id == user.id:
             await guild.leave()
     blocked = Configuration.get_persistent_var("user_blocklist", [])
     blocked.append(user.id)
     Configuration.set_persistent_var("user_blocklist", blocked)
     await MessageUtils.send_to(ctx, "YES", f"{Utils.clean_user(user)} (``{user.id}``) has been added to the blocked users list", translate=False)
     await GearbotLogging.bot_log(f"{Utils.clean_user(user)} (``{user.id}``) has been added to the blocked users list by {Utils.clean_user(ctx.author)}")
Beispiel #3
0
 async def blacklist(self, ctx, guild: Guild):
     blocked = Configuration.get_persistent_var("blacklist", [])
     blocked.append(guild.id)
     Configuration.set_persistent_var("blacklist", blocked)
     await guild.leave()
     await MessageUtils.send_to(
         ctx,
         "YES",
         f"{Utils.escape_markdown(guild.name)} (``{guild.id}``) has been added to the blacklist",
         translate=False)
Beispiel #4
0
async def upload():
    new = hashlib.md5(open(f"lang/en_US.json", 'rb').read()).hexdigest()
    old = Configuration.get_persistent_var('lang_hash', '')
    if old == new:
        return
    Configuration.set_persistent_var('lang_hash', new)
    message = await tranlator_log('REFRESH', 'Uploading translation file')
    t = threading.Thread(target=upload_file)
    t.start()
    while t.is_alive():
        await asyncio.sleep(1)
    await message.edit(content=f"{Emoji.get_chat_emoji('YES')} Translations file has been uploaded")
    await update_all()
Beispiel #5
0
async def upload():
    t_info = Configuration.get_master_var("TRANSLATIONS", dict(SOURCE="SITE", CHANNEL=0, KEY="", LOGIN="", WEBROOT=""))
    if t_info["SOURCE"] == "DISABLED": return
    new = hashlib.md5(open(f"lang/en_US.json", 'rb').read()).hexdigest()
    old = Configuration.get_persistent_var('lang_hash', '')
    if old == new:
        return
    Configuration.set_persistent_var('lang_hash', new)
    message = await tranlator_log('REFRESH', 'Uploading translation file')
    t = threading.Thread(target=upload_file)
    t.start()
    while t.is_alive():
        await asyncio.sleep(1)
    await message.edit(content=f"{Emoji.get_chat_emoji('YES')} Translations file has been uploaded")
    await update_all()
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")