async def healthcheck(self): try: async with ClientSession(raise_for_status=True) as session: await session.get(self.ping_url) except ClientError as error: logger.error(f"Health check error: {error}") else: logger.debug(f"Submitted healthcheck ping to: {self.ping_url}") logger.complete()
async def _build_firmware(self, ctx: commands.Context, version, env_or_snippet, builder, clone=None): try: if not clone: clone = Clone(version) clone.clone_version() with builder(clone, env_or_snippet) as build: await ctx.send( f"Sure thing. Building env `{build.build.env}` as `{build.build.build_id}`. This will take a minute or two.", embed=WbldEmbed(ctx, build.build, self.base_url), ) build.build.author = ctx.author run = await self.bot.loop.run_in_executor(None, build.run) if run and build.build.state == State.SUCCESS: with build.build.file_binary.open("rb") as binary: dfile = File( binary, filename= f"wled_{build.build.env}_{version}_{build.build.build_id}.bin" ) await ctx.send( embed=WbldEmbed(ctx, build.build, self.base_url), file=dfile, content= f"Good news, {ctx.author.mention}! Your build `{build.build.build_id}` for `{build.build.env}` has succeeded.", ) else: await ctx.send( embed=WbldEmbed(ctx, build.build, self.base_url), content= f"Sorry, {ctx.author.mention}. There was a problem building. See logs with: `{ctx.prefix}build log {build.build.build_id}`", ) logger.error( f"Error building firmware for `{build.build.env}` against `{version}`." ) except ReferenceException as error: await ctx.send(f"{error}: {version}") except ( CustomConfigException, MissingSectionHeaderError, ParsingError, ) as error: await ctx.send( content= f"Config Errror:\n\n{error}\n\nCheck your configuration and see help using: `{ctx.prefix}help`" )
def run(self, variables=None, targets=None, silent=False, verbose=False, jobs=2): timer_start = timer() if not variables: variables = { "pioenv": self.build.env, "project_config": self.project_config.path } if not targets: targets = [] try: options = self.project_config.items(env=self.build.env, as_dict=True) platform = options["platform"] logger.debug(f"Building {self.build.env} for {platform}") except KeyError: logger.error(f"Couldn't find platform for: {self.build.env}") self.build.state = State.FAILED return self.build try: factory = PlatformFactory.new(platform) except UnknownPlatform: self.platform_install(platform=platform, skip_default_package=True) factory = PlatformFactory.new(platform) log_combined = self.build.file_log.open("w") with redirect_stdout(log_combined), redirect_stderr(log_combined): self.build.state = State.BUILDING run = factory.run(variables, targets, silent, verbose, jobs) if run and run["returncode"] == 0: self.gather_files([open(self.firmware_filename, "rb")]) self.build.state = State.SUCCESS else: self.build.state = State.FAILED timer_end = timer() duration = float(timer_end - timer_start) self.build.duration = duration return self.build
def __init__(self, clone: Clone, env): self.kind = Kind.BUILTIN self.build = BuildModel(kind=self.kind, env=env, version=clone.version, sha1=str(clone.sha1)) self.clone = clone self.path = self.clone.path self.package_manager = None self._old_dir = None self.project_config = None if not is_platformio_project(self.path): logger.error(f"Raising FileNotFoundError for path: {self.path}") raise FileNotFoundError(self.path)
BASE_URL = os.getenv("BASE_URL", "https://wbld.app") TOKEN = os.getenv("DISCORD_TOKEN") PING_URL = os.getenv("PING_URL") PREFIXES = [os.getenv("DISCORD_PREFIX", "./")] DEFAULT_BRANCH = os.getenv("DEFAULT_BRANCH", "main") class Bot(commands.Bot): def __init__(self, **kwargs): super(Bot, self).__init__(**kwargs) async def on_ready(self): logger.info("{} has connected to Discord!", self.user) logger.complete() bot = Bot( command_prefix=PREFIXES, case_insensitive=True, description="A WLED firmware Discord bot.", ) if __name__ == "__main__": if TOKEN: if PING_URL: bot.add_cog(Health(bot, PING_URL)) bot.add_cog(WbldCog(bot, BASE_URL, DEFAULT_BRANCH)) bot.run(TOKEN) else: logger.error("Please set your DISCORD_TOKEN.")