Skip to content

Commit

Permalink
Merge pull request #59 from Quantum-0/main
Browse files Browse the repository at this point in the history
Add flag ALLOW_ALL_USERS_IN_GROUPS
  • Loading branch information
ruecat authored Jun 9, 2024
2 parents 847e501 + ddbdf98 commit 13f530f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
TOKEN=0123
ADMIN_IDS=000,111
USER_IDS=000,111
ALLOW_ALL_USERS_IN_GROUPS=0
INITMODEL=llama-2
TIMEOUT=3000

Expand Down
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,17 @@ The official image is available at dockerhub: [ruecat/ollama-telegram](https://h
```
## Environment Configuration
| Parameter | Description | Required? | Default Value | Example |
|:-----------------:|:---------------------------------------------------------------------------------------------------------------------:|:---------:|:-------------:|:-----------------------------------------------------:|
| `TOKEN` | Your **Telegram bot token**.<br/>[[How to get token?]](https://core.telegram.org/bots/tutorial#obtain-your-bot-token) | Yes | `yourtoken` | MTA0M****.GY5L5F.****g*****5k |
| `ADMIN_IDS` | Telegram user IDs of admins.<br/>These can change model and control the bot. | Yes | | 1234567890<br/>**OR**<br/>1234567890,0987654321, etc. |
| `USER_IDS` | Telegram user IDs of regular users.<br/>These only can chat with the bot. | Yes | | 1234567890<br/>**OR**<br/>1234567890,0987654321, etc. |
| `INITMODEL` | Default LLM | No | `llama2` | mistral:latest<br/>mistral:7b-instruct |
| `OLLAMA_BASE_URL` | Your OllamaAPI URL | No | | localhost<br/>host.docker.internal |
| `OLLAMA_PORT` | Your OllamaAPI port | No | 11434 | |
| `TIMEOUT` | The timeout in seconds for generating responses | No | 3000 | |
| Parameter | Description | Required? | Default Value | Example |
|:---------------------------:|:---------------------------------------------------------------------------------------------------------------------:|:---------:|:-------------:|:-----------------------------------------------------:|
| `TOKEN` | Your **Telegram bot token**.<br/>[[How to get token?]](https://core.telegram.org/bots/tutorial#obtain-your-bot-token) | Yes | `yourtoken` | MTA0M****.GY5L5F.****g*****5k |
| `ADMIN_IDS` | Telegram user IDs of admins.<br/>These can change model and control the bot. | Yes | | 1234567890<br/>**OR**<br/>1234567890,0987654321, etc. |
| `USER_IDS` | Telegram user IDs of regular users.<br/>These only can chat with the bot. | Yes | | 1234567890<br/>**OR**<br/>1234567890,0987654321, etc. |
| `INITMODEL` | Default LLM | No | `llama2` | mistral:latest<br/>mistral:7b-instruct |
| `OLLAMA_BASE_URL` | Your OllamaAPI URL | No | | localhost<br/>host.docker.internal |
| `OLLAMA_PORT` | Your OllamaAPI port | No | 11434 | |
| `TIMEOUT` | The timeout in seconds for generating responses | No | 3000 | |
| `ALLOW_ALL_USERS_IN_GROUPS` | Allows all users in group chats interact with bot without adding them to USER_IDS list | No | 0 | |
## Credits
Expand Down
3 changes: 3 additions & 0 deletions bot/func/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ollama_base_url = os.getenv("OLLAMA_BASE_URL")
ollama_port = os.getenv("OLLAMA_PORT", "11434")
log_level_str = os.getenv("LOG_LEVEL", "INFO")
allow_all_users_in_groups = bool(int(os.getenv("ALLOW_ALL_USERS_IN_GROUPS", "0")))
log_levels = list(logging._levelToName.values())
timeout = os.getenv("TIMEOUT", "3000")
if log_level_str not in log_levels:
Expand Down Expand Up @@ -66,6 +67,8 @@ async def wrapper(message: types.Message = None, query: types.CallbackQuery = No
else:
if message:
if message and message.chat.type in ["supergroup", "group"]:
if allow_all_users_in_groups:
return await func(message)
return
await message.answer("Access Denied")
elif query:
Expand Down

0 comments on commit 13f530f

Please sign in to comment.