2018-02-06 13:29:46 -05:00
|
|
|
# Telegram Bot
|
2018-01-28 18:29:58 -05:00
|
|
|
|
2018-02-10 10:37:03 -05:00
|
|
|
- Deletes messages matching specified patterns
|
|
|
|
- Bans users for posting messagses matching specified patterns
|
|
|
|
- Bans users with usernames matching specified patterns
|
|
|
|
- Records logs of converstations
|
2018-01-28 18:29:58 -05:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2018-01-29 00:29:50 -05:00
|
|
|
- Required: Python 3.x, pip, PostgreSQL
|
2018-02-10 10:37:03 -05:00
|
|
|
- Create virtualenv
|
2018-01-28 18:29:58 -05:00
|
|
|
- Clone this repo
|
2018-01-29 00:29:50 -05:00
|
|
|
- `pip install --upgrade -r requirements.txt`
|
2018-01-28 18:29:58 -05:00
|
|
|
|
2018-01-30 18:28:00 -05:00
|
|
|
## Database setup
|
|
|
|
- Store database URL in environment variable.
|
2018-01-29 00:29:50 -05:00
|
|
|
```
|
2018-01-30 18:28:00 -05:00
|
|
|
export TELEGRAM_BOT_POSTGRES_URL="postgresql://<user>:<password>@localhost:5432/<databasename>"
|
2018-01-29 00:29:50 -05:00
|
|
|
```
|
|
|
|
- Run: `python model.py` to setup the DB tables.
|
2018-01-30 18:28:00 -05:00
|
|
|
|
2018-02-10 10:37:03 -05:00
|
|
|
## Setup
|
|
|
|
|
|
|
|
- Create a Telegram bot by talking to `@BotFather` : https://core.telegram.org/bots#creating-a-new-bot
|
|
|
|
- Use `/setprivacy` with `@BotFather` in order to allow it to see all messages in a group.
|
|
|
|
- Store your Telegram Bot Token in environment variable `TELEGRAM_BOT_TOKEN`. It will look similar to this:
|
|
|
|
|
|
|
|
```
|
|
|
|
export TELEGRAM_BOT_TOKEN="4813829027:ADJFKAf0plousH2EZ2jBfxxRWFld3oK34ya"
|
|
|
|
```
|
|
|
|
- Create your Telegram group.
|
|
|
|
- Add your bot to the group like so: https://stackoverflow.com/questions/37338101/how-to-add-a-bot-to-a-telegram-group
|
|
|
|
- Make your bot an admin in the group
|
|
|
|
|
|
|
|
## Configuring patterns
|
|
|
|
|
|
|
|
- Regex patterns will be read from the following env variables
|
|
|
|
- `MESSAGE_BAN_PATTERNS` Messages matching this will ban the user.
|
|
|
|
- `MESSAGE_HIDE_PATTERNS` Messages matching this will be hidden/deleted
|
|
|
|
- `NAME_BAN_PATTERNS` Users with usernames or first/last names maching this will be banned from the group.
|
|
|
|
- `SAFE_USER_IDS` User ID's that are except from these checkes. Note that the bot cannot ban admin users, but can delete their messages.
|
|
|
|
|
|
|
|
Sample bash file to set `MESSAGE_BAN_PATTERNS`:
|
|
|
|
```
|
|
|
|
read -r -d '' MESSAGE_BAN_PATTERNS << 'EOF'
|
2018-02-10 10:38:25 -05:00
|
|
|
# ETH Address
|
2018-02-10 10:37:03 -05:00
|
|
|
# e.g. F8C8405e85Cfe42551DEfeB2a4548A33bb3DF840
|
|
|
|
[0-9a-fA-F]{40,40}
|
2018-02-10 10:38:25 -05:00
|
|
|
# BTC Address
|
|
|
|
# e.g. 13qt9rCA2CQLZedmUuDiPkwdcAJLsuTvLm
|
2018-02-10 10:37:03 -05:00
|
|
|
|[0-9a-fA-Z]{34,34}
|
|
|
|
EOF
|
|
|
|
```
|
|
|
|
|
2018-01-30 18:28:00 -05:00
|
|
|
## Running the bot
|
2018-02-10 10:37:03 -05:00
|
|
|
- Run: `python bot.py` to start.
|
2018-01-30 18:28:00 -05:00
|
|
|
- Messages will be displayed on `stdout` as they are logged.
|
2018-02-10 10:37:03 -05:00
|
|
|
|