aboutsummaryrefslogtreecommitdiffstats
path: root/arthur/exts/systems/system_information.py
diff options
context:
space:
mode:
authorGravatar jchristgit <[email protected]>2024-05-31 20:13:25 +0200
committerGravatar GitHub <[email protected]>2024-05-31 20:13:25 +0200
commit61cfcc4dc34fc2f1440e2963ef87e85416b6373e (patch)
treeea0846e43aa4c3495a5448d97c00e80e3c3f37a0 /arthur/exts/systems/system_information.py
parentMerge pull request #197 from python-discord/improve-friendliness (diff)
parentAdd support for fetching software information (diff)
Merge pull request #198 from python-discord/system-software-interaction
Add support for fetching software information
Diffstat (limited to 'arthur/exts/systems/system_information.py')
-rw-r--r--arthur/exts/systems/system_information.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/arthur/exts/systems/system_information.py b/arthur/exts/systems/system_information.py
index eafde8d..fddfacc 100644
--- a/arthur/exts/systems/system_information.py
+++ b/arthur/exts/systems/system_information.py
@@ -5,14 +5,16 @@ from datetime import datetime
import aiohttp
from discord import Message
-from discord.ext.commands import Cog
+from discord.ext.commands import Cog, Context, command
from loguru import logger
from arthur.apis.systems import lib9front
from arthur.bot import KingArthur
from arthur.config import CONFIG
-BLOGCOM = "https://git.9front.org/plan9front/plan9front/HEAD/lib/blogcom/raw"
+BASE_RESOURCE = "https://git.9front.org/plan9front/plan9front/HEAD/{}/raw"
+BLOGCOM = BASE_RESOURCE.format("lib/blogcom")
+BULLSHIT = BASE_RESOURCE.format("lib/bullshit")
THRESHOLD = 0.01
MIN_MINUTES = 30
BLOG_ABOUT_IT_THRESHOLD = 1000
@@ -29,16 +31,25 @@ class SystemInformation(Cog):
def __init__(self, bot: KingArthur) -> None:
self.bot = bot
- self.cached_data = None
+ self.cached_blogcom = None
+ self.cached_bullshit = None
self.last_sent = None
async def fetch_blogcom(self) -> str:
"""Fetch the blogcom file from the upstream location, or return the cached copy."""
- if not self.cached_data:
+ if not self.cached_blogcom:
async with aiohttp.ClientSession() as session, session.get(BLOGCOM) as resp:
- self.cached_data = await resp.text()
+ self.cached_blogcom = await resp.text()
- return self.cached_data
+ return self.cached_blogcom
+
+ async def fetch_bullshit(self) -> str:
+ """Fetch the bullshit file from the upstream location, or return the cached copy."""
+ if not self.cached_bullshit:
+ async with aiohttp.ClientSession() as session, session.get(BULLSHIT) as resp:
+ self.cached_bullshit = await resp.text()
+
+ return self.cached_bullshit
@Cog.listener()
async def on_message(self, msg: Message) -> None:
@@ -80,6 +91,13 @@ class SystemInformation(Cog):
self.last_sent = datetime.utcnow()
+ @command(name="software")
+ async def software(self, ctx: Context) -> None:
+ """Return information on installed and available software."""
+ bullshit = await self.fetch_bullshit()
+ program = lib9front.generate_buzzwords(bullshit)
+ await ctx.reply(program)
+
async def setup(bot: KingArthur) -> None:
"""Add cog to bot."""