commit
2cc416ac00
@ -0,0 +1,6 @@
|
||||
/venv/
|
||||
/crypto_store/
|
||||
/session.txt
|
||||
/.env
|
||||
/.idea
|
||||
/config.toml
|
@ -0,0 +1,6 @@
|
||||
/venv/
|
||||
/crypto_store/
|
||||
/session.txt
|
||||
/.env
|
||||
/.idea
|
||||
/config.toml
|
@ -0,0 +1,10 @@
|
||||
FROM python:3.10-slim
|
||||
|
||||
WORKDIR ./code
|
||||
|
||||
COPY ./requirements.txt .
|
||||
|
||||
RUN pip install python-olm --extra-index-url https://gitlab.matrix.org/api/v4/projects/27/packages/pypi/simple
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
COPY . .
|
@ -0,0 +1,24 @@
|
||||
### This is a template for writing a bot using simplematrixbotlib
|
||||
|
||||
#### Setup
|
||||
|
||||
First clone repo and create `.env` and `config.toml`
|
||||
|
||||
Examples:
|
||||
|
||||
`.env`
|
||||
```dotenv
|
||||
USERNAME=@catbot:example.com
|
||||
PASSWORD=password
|
||||
SERVER=https://example.com
|
||||
```
|
||||
|
||||
[allowlist and blocklist formats](https://simple-matrix-bot-lib.readthedocs.io/en/latest/examples.html#id2)
|
||||
|
||||
`config.toml`
|
||||
```toml
|
||||
[simplematrixbotlib.config]
|
||||
allowlist = []
|
||||
blocklist = []
|
||||
admin_id = '@admin:example.com'
|
||||
```
|
@ -0,0 +1,4 @@
|
||||
[simplematrixbotlib.config]
|
||||
allowlist = []
|
||||
blocklist = []
|
||||
admin_id = '@admin:example.com'
|
@ -0,0 +1,12 @@
|
||||
version: '3'
|
||||
|
||||
services:
|
||||
bot:
|
||||
build: .
|
||||
volumes:
|
||||
- '.:/code'
|
||||
- './crypto_store/:/code/crypto_store/'
|
||||
- './session.txt:/code/session.txt'
|
||||
command: 'python src/main.py'
|
||||
env_file: '.env'
|
||||
|
@ -0,0 +1,5 @@
|
||||
simplematrixbotlib~=2.8.0
|
||||
environs~=9.5.0
|
||||
aiohttp~=3.8.3
|
||||
python-olm
|
||||
matrix-nio[e2e]
|
@ -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)
|
||||
|
@ -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))
|
@ -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()
|
Loading…
Reference in new issue