Made targets work with a json
This commit is contained in:
@@ -77,7 +77,7 @@ class HealthBot(discord.Client):
|
||||
session = await self._ensure_session()
|
||||
return await checks.run_checks(session, config.CHECK_TIMEOUT)
|
||||
|
||||
def build_embed(self, results):
|
||||
def build_embed(self, results, using_backup=False):
|
||||
color = _health_color(results)
|
||||
embed = discord.Embed(
|
||||
title='Service Health',
|
||||
@@ -115,14 +115,20 @@ class HealthBot(discord.Client):
|
||||
lines.append(f'**DNS resolution ({label})** {val}')
|
||||
|
||||
embed.add_field(name=r['name'], value='\n'.join(lines), inline=False)
|
||||
embed.set_footer(text=f'Updates every {config.CHECK_INTERVAL}s')
|
||||
embed.set_footer(text=self._footer_text(using_backup))
|
||||
return embed
|
||||
|
||||
def _footer_text(self, using_backup):
|
||||
text = f'Updates every {config.CHECK_INTERVAL}s'
|
||||
if using_backup:
|
||||
text += ' · ⚠ targets.json invalid — using last known-good config'
|
||||
return text
|
||||
|
||||
async def update_embeds(self):
|
||||
if not self.status_messages:
|
||||
return
|
||||
results = await self.run_checks()
|
||||
embed = self.build_embed(results)
|
||||
results, using_backup = await self.run_checks()
|
||||
embed = self.build_embed(results, using_backup)
|
||||
|
||||
kept = []
|
||||
for entry in self.status_messages:
|
||||
@@ -172,8 +178,14 @@ bot = HealthBot()
|
||||
@bot.tree.command(name='status', description='Post a live-updating health embed for the services')
|
||||
async def status(interaction: discord.Interaction):
|
||||
await interaction.response.defer()
|
||||
results = await bot.run_checks()
|
||||
embed = bot.build_embed(results)
|
||||
try:
|
||||
results, using_backup = await bot.run_checks()
|
||||
except checks.TargetsConfigError as exc:
|
||||
await interaction.followup.send(
|
||||
f'Could not load targets config: {exc}', ephemeral=True,
|
||||
)
|
||||
return
|
||||
embed = bot.build_embed(results, using_backup)
|
||||
|
||||
existing = next(
|
||||
(m for m in bot.status_messages if m['channel_id'] == interaction.channel_id),
|
||||
|
||||
Reference in New Issue
Block a user