fixed templates bug, added templates redacting

This commit is contained in:
D3M0N 2025-03-25 19:08:22 +05:00
parent f1021f5ade
commit 886423bfba
4 changed files with 23 additions and 10 deletions

View file

@ -35,7 +35,7 @@ class BaseModule:
def _register_command(self, method: Callable):
command_info = getattr(method, "_command_info")
required_level = getattr(method, "_required_level", 0) # Уровень прав по умолчанию
required_level = getattr(method, "_required_level", 0)
command = Command(
name=command_info["name"],
description=command_info["description"],
@ -52,7 +52,7 @@ class BaseModule:
logger.warning(f"Parent command '{subcommand_info['parent_name']}' not found for subcommand '{subcommand_info['name']}'")
return
required_level = getattr(method, "_required_level", 0) # Уровень прав по умолчанию
required_level = getattr(method, "_required_level", 0)
subcommand = Command(
name=subcommand_info["name"],
description=subcommand_info["description"],

View file

@ -55,7 +55,7 @@ class CommandProcessor:
self.commands[command.name] = command
async def execute_command(self, room: MatrixRoom, command_message: str, event: Event):
parts = command_message.split()
parts = command_message.split(" ")
if not parts:
return

View file

@ -8,7 +8,7 @@ from typing import Dict, List, Optional, Any
from datetime import datetime
import feedparser
from nio import MatrixRoom, Event
from nio import MatrixRoom, Event, RoomMessageText
from core.bot_interface import BotInterface
from core.base_module import BaseModule
@ -203,7 +203,7 @@ class RSSModule(BaseModule):
await self.send_message(room.room_id, "Use `template add`, `template set`, `template del`, `template set_default`, `template list` subcommands.")
@template_command.subcommand("add", "Add a new template.", required_level=50)
async def template_add(self, room: MatrixRoom, args: List[str], event: Event):
async def template_add(self, room: MatrixRoom, args: List[str], event: RoomMessageText):
if len(args) < 2:
await self.send_message(room.room_id, "Usage: `template add <name> <content>`")
return
@ -214,10 +214,6 @@ class RSSModule(BaseModule):
if room.room_id not in self._templates:
self._templates[room.room_id] = {"default_template": None, "templates": {}}
if name in self._templates[room.room_id]["templates"]:
await self.send_message(room.room_id, f"Template with name {name} already exists.")
return
self._templates[room.room_id]["templates"][name] = content
self.save_subscriptions()
await self.send_message(room.room_id, f"Template {name} added.")

View file

@ -1,3 +1,20 @@
{
"subscriptions": {
"!fXVlXeZuhrwqEVAQoK:matrix.org": [
{
"feed_url": "https://i.orehus.club/feed/channel/UCkK9UDm_ZNrq_rIXCz3xCGA",
"last_updated": "2025-03-25T19:07:19.029190",
"template_name": "video"
}
]
},
"templates": {
"!fXVlXeZuhrwqEVAQoK:matrix.org": {
"default_template": null,
"templates": {
"video": "**[$feed_title] [$title]($link)**<details><summary>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435</summary> > $summary </details>",
"article": "[{feed_title}] [{title}]({link})\n> {summary}"
}
}
}
}