Try this bot out at dst212bot.t.me. Updates at dst212botnews.t.me.
Note that this is just a random project which offers commands I often need when I'm using Telegram. Also, I don't like the snek, but pyrogram
is cool.
help
- get further info about command usagestart
- get a warm welcomesettings
- customize bot's preferencesadmin
- manage bot's configurationtranslate
- translate a message into another languagetts
- text to speechqr
- create or read a qr codewordfor
- get a word by an input definitionpokemon
- data about Pokémonpogo
- data about Pokémon GOencode
- encode input text from and into binary, base64 or simple textscore
- manage the scores created in a chatcounter
- manage the counters created in a chatrandom
- generate a random numberpickrandom
- pick a random item from a listscramble
- randomize input textsay
- make the bot say somethinglen
- get the length of a messagecount
- count the messages sent in a chatinfo
- get info about a chathey
- contact an admin through the botcredits
- show credits
First, install the required python packages (maybe into a virtual environment):
$ python3 -m pip install -r requirements.txt
Ensure having a bot token provided by BotFather and an API key (required by pyrogram
) which can be set at my.telegram.org.
Create a file named variables.py
in the root folder of the repository and put the bot token and the API key in there, so as to make it look like this:
BOTNAME = "dst212bot" # you can put whatever name you want here
TOKEN = "0123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi"
API_ID = "12345678"
API_HASH = "c2306f38edaeb5694c37cdf52b7d573d"
To start the bot, just launch the main.py
script:
$ chmod +x main.py
$ ./main.py
The bot's configuration can be edited while the bot is running through the /admin
command. The bot won't have any admin the first time it's started, though.
You can add a Telegram user ID (retrievable with /info
) to the JSON file created at data/config.json
to make them admin, like this:
{
"admin": [448025569, 1390873424],
"log": [],
"helper": [],
"support": [],
"blocked": []
}
Then restart the bot (killing it or CTRL-C
-ing it or whatever you want). Note that admins can restart the bot using the /reboot
command. This won't work the first time as nobody is an admin unless the configuration file is manually created before.
You may want to edit other things manually:
-
blocked
: blocked chats (users or groups who won't be able to use the bot); -
helper
: users who can reply to feedback sent with /hey (also users inadmin
can do that); -
log
: chats logging bot events (when the bot starts or stops, errors... but not /hey feedback); -
support
: chats receiving feedback sent with /hey.
You can put chats' ids in log
and support
or a pair of [id, topic]
where topic
is the id of the first message of a topic, like this:
{
...
"log": [448025569, [-1001706967970, 5]],
...
}
You can retrieve group and topic info by sending /id
in the desired chat; when in a topic, Reply to
or Top message
refers to the topic ID (the first message).
The script located at commands/pokemongo/fetch_pokedex.py
fetches the Pokémon Go pokédex from pokemondb.net and saves it to data/cache/pogo/pokedex.json
upon the first start. It can be run manually (this way it creates the file into the running directory).
The TODO list is just there to make the project look professional (even though it isn't) and it serves as a common TODO list. You may want to check it out and you may suggest new features too (any constructive criticism is welcome, you can yell at me through any of my contacts available here).
Used libraries:
pyrogram
: Telegram clientopencv-python
: QR code detection and decodingpyqrcode
: QR code generationgoogletrans-py
: Translation APIsgtts
: Text to speech APIsBeautifulSoup
: HTML parserpsutil
: processes info gathering
Data sources:
- Reverse Dictionary: https://reversedictionary.org
- Pokémon: https://pokeapi.co/
- Pokémon GO: https://pokemondb.net/