Skip to content
This repository has been archived by the owner on Dec 13, 2024. It is now read-only.

Commit

Permalink
Blacken everything
Browse files Browse the repository at this point in the history
  • Loading branch information
gingershaped committed Dec 8, 2023
1 parent 368061d commit 519cc98
Show file tree
Hide file tree
Showing 16 changed files with 360 additions and 128 deletions.
26 changes: 20 additions & 6 deletions vyxalbot2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
from vyxalbot2.services.discord import DiscordService
from vyxalbot2.services.se import SEService
from vyxalbot2.userdb import UserDB
from vyxalbot2.types import CommonData, PublicConfigType, PrivateConfigType, MessagesType
from vyxalbot2.types import (
CommonData,
PublicConfigType,
PrivateConfigType,
MessagesType,
)

__version__ = "2.0.0"

Expand All @@ -42,9 +47,18 @@ def __init__(
self.privkey = f.read()

async def run(self):
userDB = UserDB(AsyncIOMotorClient(self.privateConfig["mongoUrl"]), self.privateConfig["database"])
userDB = UserDB(
AsyncIOMotorClient(self.privateConfig["mongoUrl"]),
self.privateConfig["database"],
)

ghApp = GitHubApplication(self.publicConfig, self.privkey, self.privateConfig["appID"], self.privateConfig["account"], self.privateConfig["webhookSecret"])
ghApp = GitHubApplication(
self.publicConfig,
self.privkey,
self.privateConfig["appID"],
self.privateConfig["account"],
self.privateConfig["webhookSecret"],
)
reactions = Reactions(self.messages, self.privateConfig["chat"]["ignore"])

common = CommonData(
Expand All @@ -55,7 +69,7 @@ async def run(self):
0,
datetime.now(),
userDB,
ghApp
ghApp,
)
self.se = await SEService.create(reactions, common)
self.discord = await DiscordService.create(reactions, common)
Expand All @@ -68,7 +82,7 @@ async def run(self):
async def shutdown(self, _):
await self.se.shutdown()
await self.discord.shutdown()


def run():
PUBLIC_CONFIG_PATH = os.environ.get("VYXALBOT_CONFIG_PUBLIC", "config.json")
Expand Down Expand Up @@ -96,4 +110,4 @@ def run():
STORAGE_PATH,
statuses,
)
run_app(app.run(), port=privateConfig["port"])
run_app(app.run(), port=privateConfig["port"])
2 changes: 1 addition & 1 deletion vyxalbot2/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from vyxalbot2 import run

run()
run()
20 changes: 15 additions & 5 deletions vyxalbot2/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

from vyxalbot2.types import EventInfo


class Command(dict[str, Self]):
def __init__(self, name: str, doc: str, impl: Callable[..., AsyncGenerator[Any, None]]):
def __init__(
self, name: str, doc: str, impl: Callable[..., AsyncGenerator[Any, None]]
):
super().__init__()
self.name = name
self.helpStr = doc
Expand All @@ -35,7 +38,10 @@ def fullHelp(self):
parameters.append(f"[{parameter.name}: {typeString}]")
else:
parameters.append(f"<{parameter.name}: {typeString}>")
return (f"`!!/{self.name} " + " ".join(parameters)).strip() + "`: " + self.helpStr
return (
(f"`!!/{self.name} " + " ".join(parameters)).strip() + "`: " + self.helpStr
)


class CommandSupplier:
def __init__(self):
Expand All @@ -56,7 +62,11 @@ def genCommands(self):
doc = "…"
else:
doc = attr.__doc__
name = re.sub(r"([A-Z])", lambda match: " " + match.group(0).lower(), attr.__name__.removesuffix("Command"))
name = re.sub(
r"([A-Z])",
lambda match: " " + match.group(0).lower(),
attr.__name__.removesuffix("Command"),
)
commands[name] = Command(name, doc, attr)
return commands

return commands
33 changes: 27 additions & 6 deletions vyxalbot2/commands/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from vyxalbot2.types import CommonData, EventInfo
from vyxalbot2.util import RAPTOR


class StatusMood(Enum):
MESSAGE = "message"
BORING = "boring"
Expand All @@ -22,6 +23,7 @@ class StatusMood(Enum):
CRYPTIC = "cryptic"
GOOFY = "goofy"


class CommonCommands(CommandSupplier):
def __init__(self, common: CommonData):
super().__init__()
Expand All @@ -41,7 +43,9 @@ def status(self):
f"Errors since startup: {self.common.errorsSinceStartup}"
)

async def statusCommand(self, event: EventInfo, mood: StatusMood = StatusMood.MESSAGE):
async def statusCommand(
self, event: EventInfo, mood: StatusMood = StatusMood.MESSAGE
):
"""I will tell you what I'm doing (maybe)."""
match mood:
case StatusMood.MESSAGE:
Expand All @@ -54,21 +58,33 @@ async def statusCommand(self, event: EventInfo, mood: StatusMood = StatusMood.ME
case StatusMood.BORING:
yield self.status()
case StatusMood.EXCITING:
yield "\n".join(map(lambda line: line + ("!" * random.randint(2, 5)), self.status().upper().splitlines()))
yield "\n".join(
map(
lambda line: line + ("!" * random.randint(2, 5)),
self.status().upper().splitlines(),
)
)
case StatusMood.TINGLY:
uwu = uwuipy(None, 0.3, 0.2, 0.2, 1) # type: ignore Me when the developers of uwuipy don't annotate their types correctly
yield uwu.uwuify(self.status())
case StatusMood.SLEEPY:
status = self.status()
yield (
"\n".join(status.splitlines())[:random.randint(1, len(status.splitlines()))]
"\n".join(status.splitlines())[
: random.randint(1, len(status.splitlines()))
]
+ " *yawn*\n"
+ "z" * random.randint(5, 10)
)
case StatusMood.CRYPTIC:
yield codecs.encode(self.status(), "rot13")
case StatusMood.GOOFY:
yield "\n".join(map(lambda line: line + "🤓" * random.randint(1, 3), self.status().splitlines()))
yield "\n".join(
map(
lambda line: line + "🤓" * random.randint(1, 3),
self.status().splitlines(),
)
)

async def coffeeCommand(self, event: EventInfo, target: str = "me"):
"""Brew some coffee."""
Expand Down Expand Up @@ -112,13 +128,16 @@ async def cookieCommand(self, event: EventInfo):
async def deliterateifyCommand(self, event: EventInfo, code: str):
"""Convert literate code to sbcs"""
async with ClientSession() as session:
async with session.post(self.common.privateConfig["tyxalInstance"] + "/deliterateify", data=code) as response:
async with session.post(
self.common.privateConfig["tyxalInstance"] + "/deliterateify", data=code
) as response:
if response.status == 400:
yield f"Failed to deliterateify: {await response.text()}"
elif response.status == 200:
yield f"`{await response.text()}`"
else:
yield f"Tyxal sent back an error response! ({response.status})"

# Add an alias
async def delitCommand(self, event: EventInfo, code: str):
async for line in self.deliterateifyCommand(event, code):
Expand All @@ -134,7 +153,9 @@ async def pullCommand(self, event: EventInfo):

async def commitCommand(self, event: EventInfo):
"""Check the commit the bot is running off of"""
result = subprocess.run(["git", "show", "--oneline", "-s", "--no-color"], capture_output=True)
result = subprocess.run(
["git", "show", "--oneline", "-s", "--no-color"], capture_output=True
)
if result.returncode != 0:
yield "Failed to get commit info!"
else:
Expand Down
2 changes: 1 addition & 1 deletion vyxalbot2/commands/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

class DiscordCommands(CommonCommands):
def __init__(self, common: CommonData):
super().__init__(common)
super().__init__(common)
Loading

0 comments on commit 519cc98

Please sign in to comment.