Python maubot(matrix) plugin basteln

BLACKDIAMONT

Lt. Commander
Registriert
Nov. 2012
Beiträge
1.475
Moinsen,

ich bastel an Matrix (riot.im) und habe natürlich auch bots entdeckt .... leider ist alles in python und wirklich Beispiele ausser "hello world" gibts dafür nicht ....

Code abschauen usw hilft zwar manchmal aber aktuell steh ich vor Problemen^^
Hoffe ihr könnt mir evtl unter die Arme greifen, ohne das ich jetz Tage mit python lernen für nen mini-Plugin verbringen muss ..

Abschauen tu ich hier

Was ich gebastelt habe:
Python:
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from maubot import Plugin, MessageEvent
from maubot.handlers import command
from typing import List, Tuple
import re

class Config(BaseProxyConfig):
    def do_update(self, helper: ConfigUpdateHelper) -> None:
        helper.copy("commands")

@classmethod
    def get_config_class(cls) -> Type[BaseProxyConfig]:
        return Config

    async def start(self) -> None:
        self.on_external_config_update()

    def on_external_config_update(self) -> None:
        self.config.load_and_update()
        commands = self.config["commands"]

class CommandsReplyBot(Plugin):
        @command.new("commands")
        async def handler(self, event: MessageEvent) -> None:
                commands = self.config["commands"]
                #commands = "Maubot Commands:<br>!joke<br>!validation<br>!ud<br>!trump<br>!remind<br>!tmdb<br>!xkcd<br>!roll<br>!poll<br>!rss"
                await event.reply(commands, allow_html=True)

Das auskommentierte commands (nur mit der CommandsReplyBot class) funktioniert einwandfrei, allerdings will ich diese über die config dynamisch anpassen (geht über das Bot Webinterface via base-config.yaml).

Ich habe soweit alles hinzugefügt wo ich denke, das es reingehört ;)

Fehlermeldung ist -> TypeError: 'NoneType' object is not subscriptable

Jep ..... Bahnhof für mich trotz google :/


Wer kann helfen? :)
 
Okay habe es soweit hinbekommen das es zwar funktioniert, aber erhalte in den Logs noch eine Fehlermeldung:
Code:
commands += ''.join(self.base_aliases)
AttributeError: 'CommandsReplyBot' object has no attribute 'base_aliases'

Code:
Python:
from mautrix.util.config import BaseProxyConfig, ConfigUpdateHelper
from maubot import Plugin, MessageEvent
from maubot.handlers import command, event
from typing import List, Tuple, Type, Set, Optional, Any
import re

class Config(BaseProxyConfig):
        def do_update(self, helper: ConfigUpdateHelper) -> None:
                helper.copy("commands")


class CommandsReplyBot(Plugin):
        commands: str
        base_aliases: Tuple[str, ...]

        async def start(self) -> None:
                self.on_external_config_update()

        def on_external_config_update(self) -> None:
                self.config.load_and_update()
                bc = self.config["commands"]
                self.commands = bc[0] if isinstance(bc, list) else bc
                self.base_aliases = tuple(bc) if isinstance(bc, list) else (bc,)

        @classmethod
        def get_config_class(cls) -> Type[Config]:
                return Config

        @command.new("commands")
        async def handler(self, event: MessageEvent) -> None:
                commands = "Maubot Commands:"
                commands += ''.join(self.base_aliases)
                await event.reply(commands, allow_html=True)
 
theoretisch ja, er nimmt die self.config["commands"] und gibt diese auch korrekt aus.
Ich frag mal dort nach, falls keiner noch ne Idee hat :)
 

Ähnliche Themen

Zurück
Oben