Add optional whitelist or blacklist
This commit is contained in:
parent
04e38f6c44
commit
a259bd4c72
4 changed files with 26 additions and 2 deletions
6
base-config.yaml
Normal file
6
base-config.yaml
Normal file
|
@ -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"
|
2
build.sh
2
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
|
||||
|
|
16
karma/bot.py
16
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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue