Add msc command

This commit is contained in:
Nexus 2024-09-15 20:25:42 +01:00
parent ee3338df7a
commit fad2108f0d
8 changed files with 746 additions and 671 deletions

View file

@ -10,7 +10,7 @@ yt-dlp = "*"
humanize = "*" humanize = "*"
httpx = "*" httpx = "*"
ollama = "*" ollama = "*"
nio-bot = {git = "git+https://github.com/nexy7574/nio-bot.git"} nio-bot = "==1.2.0a2"
[dev-packages] [dev-packages]
ruff = "*" ruff = "*"

1364
Pipfile.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,11 +1,12 @@
# import sys # import sys
import asyncio import asyncio
import sys
import niobot import niobot
import tomllib import tomllib
import platform import platform
import logging import logging
# import tortoise import tortoise
from pathlib import Path from pathlib import Path
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -26,13 +27,13 @@ class TortoiseIntegratedBot(niobot.NioBot):
cfg: dict cfg: dict
async def start(self, **kwargs): async def start(self, **kwargs):
# url = config["database"].get("uri") url = config["database"].get("uri")
# if not url: if not url:
# log.critical("No database URI specified in config.toml - using ephemeral sqlite.") log.critical("No database URI specified in config.toml - using ephemeral sqlite.")
# url = "sqlite://:memory:" url = "sqlite://:memory:"
# sys.path.extend(("..", ".")) sys.path.extend(("..", "."))
# await tortoise.Tortoise.init(db_url=url, modules={"models": ["app.models"]}) await tortoise.Tortoise.init(db_url=url, modules={"models": ["app.models"]})
# await tortoise.Tortoise.generate_schemas() await tortoise.Tortoise.generate_schemas()
for file in (Path(__file__).parent / "./modules").glob("*.py"): for file in (Path(__file__).parent / "./modules").glob("*.py"):
if file.name.startswith("__"): if file.name.startswith("__"):
@ -54,7 +55,7 @@ bot = TortoiseIntegratedBot(
user_id=config["bot"]["user_id"], user_id=config["bot"]["user_id"],
device_id=config["bot"].get("device_id", platform.node()), device_id=config["bot"].get("device_id", platform.node()),
store_path=str(store.resolve()), store_path=str(store.resolve()),
command_prefix="h!", command_prefix=config["bot"].get("prefix", "h!"),
owner_id=config["bot"].get("owner_id") or "@nex:nexy7574.co.uk", owner_id=config["bot"].get("owner_id") or "@nex:nexy7574.co.uk",
) )
bot.cfg = config bot.cfg = config
@ -87,5 +88,5 @@ async def on_command_complete(ctx: niobot.Context, _):
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(bot.start(access_token=bot.cfg["bot"]["access_token"])) # asyncio.run(bot.start(access_token=bot.cfg["bot"]["access_token"]))
# tortoise.run_async(bot.start(access_token=bot.cfg["bot"]["access_token"])) tortoise.run_async(bot.start(access_token=bot.cfg["bot"]["access_token"]))

View file

@ -1 +1,8 @@
from tortoise import Model, fields from tortoise import Model, fields
class Account(Model):
mxid: str = fields.CharField(max_length=255, primary_key=True, generated=False)
current_balance: int = fields.IntField(default=0)
bank_balance: int = fields.IntField(default=0)
currency: str = fields.CharField(max_length=3, default="GBP")

View file

View file

@ -207,8 +207,7 @@ class EvalModule(niobot.Module):
@niobot.is_owner() @niobot.is_owner()
async def runas(self, ctx: niobot.Context, user: str, command: str, *args): async def runas(self, ctx: niobot.Context, user: str, command: str, *args):
"""Run a command as another user.""" """Run a command as another user."""
args = args or [] if args is not None and args[0] == "%null%":
if args and args[0] == "%null%":
args = tuple() args = tuple()
event = ctx.event event = ctx.event
event.sender = user event.sender = user

View file

@ -20,7 +20,7 @@ class FediversePreviewModule(niobot.Module):
@niobot.event("message") @niobot.event("message")
async def on_message(self, room: niobot.MatrixRoom, event: niobot.RoomMessage): async def on_message(self, room: niobot.MatrixRoom, event: niobot.RoomMessage):
config = self.bot.cfg.get("fediverse_preview") config = self.bot.cfg.get("fediverse_preview", {})
supported_prefixes = config.get("urls", ["https://fedi.transgender.ing"]) supported_prefixes = config.get("urls", ["https://fedi.transgender.ing"])
ignore = config.get("ignore", []) ignore = config.get("ignore", [])
if not isinstance(event, niobot.RoomMessageText): if not isinstance(event, niobot.RoomMessageText):

16
app/modules/msc_getter.py Normal file
View file

@ -0,0 +1,16 @@
import niobot
class MSCGetter(niobot.Module):
@niobot.command()
async def msc(self, ctx: niobot.Context, number: str):
"""Fetches the given MSC"""
if number.startswith("msc"):
number = number[3:]
elif number.startswith("#"):
number = number[1:]
if not number.isdigit():
return await ctx.respond("Invalid MXC number.")
return await ctx.respond(
"https://github.com/matrix-org/matrix-spec-proposals/pull/" + number
)