• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    Python
  • License
    MIT License
  • Created almost 7 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Telegram bot for controlling spam, logging, and more

origin_github_banner

Head to https://www.originprotocol.com/developers to learn more about what we're building and how to get involved.

Telegram Bot

  • Deletes messages matching specified patterns
  • Bans users for posting messages matching specified patterns
  • Bans users with usernames matching specified patterns
  • Records logs of conversations
  • Logs an English translation of any foreign languages using Google Translate
  • Uses textblob for basic sentiment analysis of both polarity and subjectivity

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"

Configuration with ENV vars

  • MESSAGE_BAN_PATTERNS : REQUIRED Regex pattern. Messages matching this will ban the user.
  • MESSAGE_HIDE_PATTERNS : REQUIRED Regex pattern. Messages matching this will be hidden/deleted
  • NAME_BAN_PATTERNS REQUIRED Regex pattern. Users with usernames or first/last names maching this will be banned from the group.
  • CHAT_IDS : REQUIRED. Comma-seperated list of IDs of chat(s) that should be monitored. To find out the ID of a chat, add the bot to a chat and type some messages there. The bot log will report an error that it got messages from chat_id not being monitored: XXX where XXX is the chat ID. e.g. -240532994,-150531679
  • TELEGRAM_BOT_TOKEN : REQUIRED. Token for bot to control. e.g. 4813829027:ADJFKAf0plousH2EZ2jBfxxRWFld3oK34ya
  • TELEGRAM_BOT_POSTGRES_URL : REQUIRED. URI for postgres instance to log activity to. e.g. postgresql://localhost/postgres
  • DEBUG : If set to anything except false, will put bot into debug mode. This means that all actions will be logged into the chat itself, and more things will be logged.
  • ADMIN_EXEMPT : If set to anything except false, admin users will be exempt from monitoring. Reccomended to be set, but useful to turn off for debugging.
  • NOTIFY_CHAT : ID of chat to report actions. Can be useful if you have an admin-only chat where you want to monitor the bot's activity. E.g. -140532994
  • CMC_API_KEY: If you want the /price bot command to work, make sure to set a CoinMarketcap API key

Download the corpus for Textblob

For sentiment analysis to work, you'll need to download the latest corpus file for textblob. You can do this by running:

python -m textblob.download_corpora

If you're running the bot on Heroku, set an environment variable named NLTK_DATA to /app/nltk_data by running:

heroku config:set NLTK_DATA='/app/nltk_data'

Message ban patterns

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

Attachments

By default, any attachments other than images or animations will cause the message to be hidden.

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.)

More Repositories

1

origin

Monorepo for our developer tools and decentralized marketplace application
JavaScript
652
star
2

security

Materials related to security: docs, checklists, processes, etc...
Solidity
199
star
3

origin-playground

Playground for us to try out new ideas, specifically around Identity (ERC 725) & the Origin Marketplace
JavaScript
159
star
4

dshop

Origin Dshop - launch your own decentralized store
JavaScript
138
star
5

origin-dollar

OUSD and OETH are stablecoins that passively accrue yield while you are holding it
JavaScript
116
star
6

origin-js

We've moved to a monorepo: https://github.com/OriginProtocol/origin
JavaScript
81
star
7

origin-website

The code powering our website
HTML
40
star
8

react-native-samsung-bks

React Native wrapper for Samsung Blockchain Keystore SDK
Java
16
star
9

origin-bridge

We've moved to a monorepo: https://github.com/OriginProtocol/origin/tree/master/infra/bridge
Python
15
star
10

minimal-proxy-example

An example implementation of a Minimal Proxy | EIP-1167
JavaScript
11
star
11

ousd-governance

OUSD Governance Portal and Contracts
Solidity
11
star
12

ousd.com

Frontend for ousd.com
TypeScript
11
star
13

nft-launchpad

Contracts for Origin's NFT platform
JavaScript
10
star
14

origin-tracer

Ethereum transactions visualization tool
TypeScript
9
star
15

origin-docs-archived

We've moved to a monorepo: https://github.com/OriginProtocol/origin/tree/master/docs
JavaScript
9
star
16

ousd-analytics

Web application to pull statistics on OUSD from the blockchain.
Python
8
star
17

website-frontend

originprotocol.com front-end
JavaScript
6
star
18

origin-box

We've moved to a monorepo: https://github.com/OriginProtocol/origin/blob/master/DEVELOPMENT.md
Shell
5
star
19

origin-defi

Origin Protocol frontend monorepo
TypeScript
4
star
20

origin-mobile

We've moved to a monorepo: https://github.com/OriginProtocol/origin/tree/master/mobile
JavaScript
3
star
21

origin-squid

Origin Subsquid
TypeScript
3
star
22

origin-squid-notifications

Subsquid for Notifications
TypeScript
3
star
23

wash-inspector

NFT trade analytics tool that identifies NFTs that have been wash traded.
TypeScript
2
star
24

origin-schemas

Example Origin listing schemas
2
star
25

civic-proxy

Handles the decrypting of user information being returned from Civic
JavaScript
2
star
26

origin-monorepo

The Origin Protocol monorepo for dApps and resuable packages across the organization
TypeScript
2
star
27

origin-devops

We've moved to a monorepo: https://github.com/OriginProtocol/origin/tree/master/devops
2
star
28

test-builds

Test builds of the Origin dapp
CSS
2
star
29

oeth.com

Frontend for oeth.com
TypeScript
2
star
30

ousd-compensation-calculation

Scripts, utilties, and data for the OUSD attack compensation
Python
1
star
31

telegram-discord-bridge

JavaScript
1
star
32

stolen

Literally the Worst Idea
JavaScript
1
star
33

origin-dollar-docs

Official documentation for OUSD. This repo is used to sync changes between Crowdin and Gitbook.
1
star
34

origin-how-to

1
star
35

oeth-dapp

The dapp for oeth integration
TypeScript
1
star
36

origin-cms

JavaScript
1
star
37

veogv

Solidity
1
star
38

story.xyz

Story.xyz frontend using Next.js
TypeScript
1
star