mirror of
https://codeberg.org/D3M0N/thread-bot.git
synced 2025-04-11 20:58:47 +02:00
fixed bug 2, changed README.md
This commit is contained in:
parent
0e5e187a7d
commit
3c5c250b07
2 changed files with 93 additions and 23 deletions
79
README.md
79
README.md
|
@ -1,3 +1,80 @@
|
|||
# thread-bot
|
||||
|
||||
An assistant to keep order in the chat room
|
||||
An assistant to keep order in the chat room
|
||||
|
||||
# 🤖 Thread Bot - An assistant to keep order in the chat room
|
||||
|
||||
Thread Bot is a simple assistant designed to maintain order in your chat room. It automatically deletes non-thread posts from users with a permission level below 50, ensuring that only authorized users can post freely. The bot requires a permission level of 50+ to function.
|
||||
|
||||
---
|
||||
|
||||
## 📋 Commands
|
||||
|
||||
- `!thread_bot help` - Displays this help message.
|
||||
|
||||
---
|
||||
|
||||
## 🛠️ Functional
|
||||
|
||||
- **Automatic Post Deletion**: The bot automatically deletes non-trad posts from users with a permission level below 50.
|
||||
- **Permission Level**: The bot requires a permission level of 50+ to operate.
|
||||
|
||||
---
|
||||
|
||||
## 🚀 Getting Started
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Docker (optional, if you want to use Docker)
|
||||
- Python 3.x
|
||||
|
||||
### Installation
|
||||
|
||||
1. **Clone the Repository**
|
||||
|
||||
```bash
|
||||
git clone https://codeberg.org/D3M0N/thread-bot.git
|
||||
cd thread-bot
|
||||
```
|
||||
|
||||
2. **Configure the Bot**
|
||||
|
||||
Rename the example configuration file and edit it to suit your needs:
|
||||
|
||||
```bash
|
||||
mv example.config.toml config.toml
|
||||
```
|
||||
|
||||
Open `config.toml` and fill in the necessary details.
|
||||
|
||||
3. **Run the Bot**
|
||||
|
||||
You can run the bot using Docker or directly with Python.
|
||||
|
||||
- **Using Docker**:
|
||||
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
- **Using Python**:
|
||||
|
||||
```bash
|
||||
python main.py
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ❓ Support
|
||||
|
||||
If you have any questions about the bot's operation, please contact the administrators.
|
||||
|
||||
---
|
||||
|
||||
## 📜 License
|
||||
|
||||
This project is licensed under the GPL v3.0 License - see the [LICENSE](LICENSE) file for details.
|
||||
|
||||
---
|
||||
|
||||
Enjoy using Thread Bot to keep your chat room organized! 🎉
|
37
main.py
37
main.py
|
@ -38,7 +38,6 @@ class ThreadBot:
|
|||
await self.client.close()
|
||||
|
||||
async def handle_invite(self, room: MatrixRoom, event: InviteMemberEvent) -> None:
|
||||
# Remove timestamp check since InviteMemberEvent doesn't have server_timestamp
|
||||
if event.state_key != self.client.user_id:
|
||||
return
|
||||
|
||||
|
@ -64,13 +63,23 @@ class ThreadBot:
|
|||
return
|
||||
|
||||
try:
|
||||
if event.body == "!thread_bot help":
|
||||
power_levels = await self.client.room_get_state_event(
|
||||
power_levels = await self.client.room_get_state_event(
|
||||
room.room_id,
|
||||
"m.room.power_levels"
|
||||
)
|
||||
user_level = power_levels.content.get("users", {}).get(event.sender, 0)
|
||||
|
||||
user_level = power_levels.content.get("users", {}).get(event.sender, 0)
|
||||
is_threaded = bool(event.source.get('content', {}).get('m.relates_to', {}).get('rel_type') == 'm.thread')
|
||||
|
||||
if not is_threaded and user_level < self.config.required_power_level:
|
||||
self.logger.info(f"Removing non-threaded message from {event.sender} in room {room.room_id}")
|
||||
await self.client.room_redact(
|
||||
room_id=room.room_id,
|
||||
event_id=event.event_id,
|
||||
reason="Messages must be in threads unless sent by admin"
|
||||
)
|
||||
return
|
||||
|
||||
if event.body == "!thread_bot help":
|
||||
if user_level < self.config.required_power_level:
|
||||
await self.client.room_send(
|
||||
room_id=room.room_id,
|
||||
|
@ -80,23 +89,7 @@ class ThreadBot:
|
|||
"body": self.config.help_message
|
||||
}
|
||||
)
|
||||
return
|
||||
|
||||
is_threaded = bool(event.source.get('content', {}).get('m.relates_to', {}).get('rel_type') == 'm.thread')
|
||||
|
||||
power_levels = await self.client.room_get_state_event(
|
||||
room.room_id,
|
||||
"m.room.power_levels"
|
||||
)
|
||||
user_level = power_levels.content.get("users", {}).get(event.sender, 0)
|
||||
|
||||
if not is_threaded and user_level < self.config.required_power_level:
|
||||
self.logger.info(f"Removing non-threaded message from {event.sender} in room {room.room_id}")
|
||||
await self.client.room_redact(
|
||||
room_id=room.room_id,
|
||||
event_id=event.event_id,
|
||||
reason="Messages must be in threads unless sent by admin"
|
||||
)
|
||||
return
|
||||
except Exception as e:
|
||||
self.logger.error(f"Error processing message in room {room.room_id}: {e}")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue