diff --git a/base-config.yaml b/base-config.yaml new file mode 100644 index 0000000..2f7aea3 --- /dev/null +++ b/base-config.yaml @@ -0,0 +1,6 @@ +# Whether or not everyone can vote +democracy: true +# The list of people to filter. +# If democracy is enabled, this is a blacklist. Otherwise this is a whitelist. +filter: +- "@user:example.com" diff --git a/build.sh b/build.sh index 4f1efe4..d5fa5ec 100755 --- a/build.sh +++ b/build.sh @@ -1,2 +1,2 @@ #!/bin/bash -zip -9r karma.mbp karma/ maubot.ini +zip -9r karma.mbp base-config.yaml karma/ maubot.ini diff --git a/karma/bot.py b/karma/bot.py index ba5ce3a..cd3219e 100644 --- a/karma/bot.py +++ b/karma/bot.py @@ -23,6 +23,7 @@ from maubot import Plugin, CommandSpec, Command, PassiveCommand, Argument, Messa from mautrix.types import (Event, StateEvent, EventID, UserID, FileInfo, MessageType, MediaMessageEventContent) from mautrix.client.api.types.event.message import media_reply_fallback_body_map +from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper from .db import make_tables, Karma, Version @@ -54,12 +55,19 @@ DOWNVOTE_TEXT = r"(?:-(?:1|-)?)" DOWNVOTE = f"^(?:{DOWNVOTE_EMOJI}|{DOWNVOTE_EMOJI_SHORTHAND}|{DOWNVOTE_TEXT})$" +class Config(BaseProxyConfig): + def do_update(self, helper: ConfigUpdateHelper) -> None: + helper.copy("democracy") + helper.copy("filter") + + class KarmaBot(Plugin): karma: Type[Karma] version: Type[Version] db: Engine async def start(self) -> None: + self.config.load_and_update() self.db = self.request_db_engine() self.karma, self.version = make_tables(self.db) self.set_command_spec(CommandSpec(commands=[ @@ -134,6 +142,10 @@ class KarmaBot(Plugin): async def vote(self, evt: MessageEvent, target: EventID, value: int) -> None: if not target: return + in_filter = evt.sender in self.config["filter"] + if self.config["democracy"] == in_filter: + await evt.reply("Sorry, you're not allowed to vote.") + return if self.karma.is_vote_event(target): await evt.reply("Sorry, you can't vote on votes.") return @@ -255,3 +267,7 @@ class KarmaBot(Plugin): async def own_karma_breakdown(self, evt: MessageEvent) -> None: await evt.reply("Not yet implemented :(") + + @classmethod + def get_config_class(cls) -> Type[BaseProxyConfig]: + return Config diff --git a/maubot.ini b/maubot.ini index b9eacd5..90a4c1f 100644 --- a/maubot.ini +++ b/maubot.ini @@ -1,5 +1,7 @@ [maubot] ID = xyz.maubot.karma -Version = 0.1.0 +Version = 0.1.1 +License = AGPL-3.0-or-later Modules = karma MainClass = KarmaBot +ExtraFiles = base-config.yaml