aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Joseph Banks <[email protected]>2020-04-11 22:44:13 +0100
committerGravatar Joseph Banks <[email protected]>2020-04-11 22:44:13 +0100
commit673869062ff49a74a2d2f8338c4d26003bee995e (patch)
treee670f0a20610d07c73cf057a8c918100daaff699
parentMerge master (diff)
Add a metric for tracking how long defcon was active
-rw-r--r--bot/cogs/defcon.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/bot/cogs/defcon.py b/bot/cogs/defcon.py
index 9197dcca3..7043c7cbb 100644
--- a/bot/cogs/defcon.py
+++ b/bot/cogs/defcon.py
@@ -126,6 +126,19 @@ class Defcon(Cog):
async def _defcon_action(self, ctx: Context, days: int, action: Action) -> None:
"""Providing a structured way to do an defcon action."""
+ try:
+ response = await self.bot.api_client.get('bot/bot-settings/defcon')
+ data = response['data']
+
+ if "enable_date" in data and action is Action.DISABLED:
+ enabled = datetime.fromisoformat(data["enable_date"])
+
+ delta = datetime.now() - enabled
+
+ self.bot.stats.timer("defcon.enabled", delta)
+ except Exception:
+ pass
+
error = None
try:
await self.bot.api_client.put(
@@ -136,6 +149,7 @@ class Defcon(Cog):
# TODO: retrieve old days count
'days': days,
'enabled': action is not Action.DISABLED,
+ 'enable_date': datetime.now().isoformat()
}
}
)
@@ -146,7 +160,7 @@ class Defcon(Cog):
await ctx.send(self.build_defcon_msg(action, error))
await self.send_defcon_log(action, ctx.author, error)
- self.bot.stats.gauge("defcon.days", days)
+ self.bot.stats.gauge("defcon.threshold", days)
@defcon_group.command(name='enable', aliases=('on', 'e'))
@with_role(Roles.admins, Roles.owners)