Initial commit

This commit is contained in:
KKlochko
2023-06-16 16:00:33 +02:00
committed by GitHub
commit 2cc416ac00
10 changed files with 131 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
import nio
import simplematrixbotlib as botlib
from .help import help_handler
def setup(bot: botlib.Bot, prefix: str):
@bot.listener.on_message_event
async def help_command(room: nio.rooms.MatrixRoom, message: nio.events.room_events.Event):
match = botlib.MessageMatch(room, message, bot, prefix=prefix)
if match.is_not_from_this_bot() and match.prefix() and match.command('help'):
await help_handler(bot=bot, room_id=room.room_id, sender=message.sender, admin_id=bot.config.admin_id)
+10
View File
@@ -0,0 +1,10 @@
import simplematrixbotlib as botlib
async def help_handler(room_id: str, bot: botlib.Bot, sender: str, admin_id: str):
msg: str = 'Hi **{}**\n\n' \
'Prefix: `!`\n' \
'Its a simplematrixbotlib template!\n' \
'Admin contact: **{}**'
await bot.api.send_markdown_message(room_id=room_id, message=msg.format(sender, admin_id))
+40
View File
@@ -0,0 +1,40 @@
from dataclasses import dataclass
from environs import Env
import simplematrixbotlib as botlib
from handlers import setup
env = Env()
env.read_env()
USERNAME = env('USERNAME')
PASSWORD = env('PASSWORD')
SERVER = env('SERVER')
@dataclass
class MyConfig(botlib.Config):
_admin_id: str = 'unknown'
_lang: str = 'en'
@property
def admin_id(self) -> str:
return self._admin_id
@admin_id.setter
def admin_id(self, value: str) -> None:
self._admin_id = value
config = MyConfig()
config.load_toml('config.toml')
config.encryption_enabled = True
config.emoji_verify = True
config.ignore_unverified_devices = True
config.store_path = './crypto_store/'
creds = botlib.Creds(SERVER, USERNAME, PASSWORD)
bot = botlib.Bot(creds, config)
PREFIX = '!'
setup(bot, prefix=PREFIX)
bot.run()