diff options
| author | 2024-05-31 20:06:10 +0200 | |
|---|---|---|
| committer | 2024-05-31 20:08:50 +0200 | |
| commit | 44722a4318328e58ec375392b9eeb19d3d328692 (patch) | |
| tree | ea0846e43aa4c3495a5448d97c00e80e3c3f37a0 | |
| parent | Merge pull request #197 from python-discord/improve-friendliness (diff) | |
Add support for fetching software information
Co-authored-by: Chris Lovering <[email protected]>
| -rw-r--r-- | arthur/exts/systems/system_information.py | 30 | 
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.""" | 
