Git Product home page Git Product logo

telegram-moderator's Introduction

Telegram Bot

  • Deletes messages matching specified patterns
  • Bans users for posting messagses matching specified patterns
  • Bans users with usernames matching specified patterns
  • Records logs of converstations

Installation

  • Required: Python 3.x, pip, PostgreSQL
  • Create virtualenv
  • Clone this repo
  • pip install --upgrade -r requirements.txt

Database setup

  • Store database URL in environment variable.
export TELEGRAM_BOT_POSTGRES_URL="postgresql://<user>:<password>@localhost:5432/<databasename>"
  • Run: python model.py to setup the DB tables.

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"

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'
# ETH Address
# e.g. F8C8405e85Cfe42551DEfeB2a4548A33bb3DF840
[0-9a-fA-F]{40,40}
# BTC Address
# e.g. 13qt9rCA2CQLZedmUuDiPkwdcAJLsuTvLm
|[0-9a-fA-Z]{34,34}
EOF

Running

Locally

  • Run: python bot.py to start logger
  • Messages will be displayed on stdout as they are logged.

On Heroku

  • You must enable the worker on Heroku app dashboard. (By default it is off.)

telegram-moderator's People

Contributors

wanderingstan avatar joshfraser avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.