Skip to content

Commit

Permalink
Add support for fetching software information
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristgit committed May 31, 2024
1 parent f1fddd3 commit 367a802
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions arthur/exts/systems/system_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
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
Expand All @@ -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:
Expand Down Expand Up @@ -80,6 +91,13 @@ async def on_message(self, msg: Message) -> None:

self.last_sent = datetime.utcnow()

@commands.command(name="software")

Check failure on line 94 in arthur/exts/systems/system_information.py

View workflow job for this annotation

GitHub Actions / lint / Lint

Ruff (F821)

arthur/exts/systems/system_information.py:94:6: F821 Undefined name `commands`
async def software(self, ctx: commands.Context) -> None:

Check failure on line 95 in arthur/exts/systems/system_information.py

View workflow job for this annotation

GitHub Actions / lint / Lint

Ruff (ARG002)

arthur/exts/systems/system_information.py:95:30: ARG002 Unused method argument: `ctx`

Check failure on line 95 in arthur/exts/systems/system_information.py

View workflow job for this annotation

GitHub Actions / lint / Lint

Ruff (F821)

arthur/exts/systems/system_information.py:95:35: F821 Undefined name `commands`
"""Return information on installed and available software."""
bullshit = await self.fetch_bullshit()
program = lib9front.generate_buzzwords(bullshit)
await msg.reply(program)

Check failure on line 99 in arthur/exts/systems/system_information.py

View workflow job for this annotation

GitHub Actions / lint / Lint

Ruff (F821)

arthur/exts/systems/system_information.py:99:15: F821 Undefined name `msg`


async def setup(bot: KingArthur) -> None:
"""Add cog to bot."""
Expand Down

0 comments on commit 367a802

Please sign in to comment.