Skip to content

dst212/dst212bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dst212bot

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.

Relevant commands

  • help - get further info about command usage
  • start - get a warm welcome
  • settings - customize bot's preferences
  • admin - manage bot's configuration
  • translate - translate a message into another language
  • tts - text to speech
  • qr - create or read a qr code
  • wordfor - get a word by an input definition
  • pokemon - data about Pokémon
  • pogo - data about Pokémon GO
  • encode - encode input text from and into binary, base64 or simple text
  • score - manage the scores created in a chat
  • counter - manage the counters created in a chat
  • random - generate a random number
  • pickrandom - pick a random item from a list
  • scramble - randomize input text
  • say - make the bot say something
  • len - get the length of a message
  • count - count the messages sent in a chat
  • info - get info about a chat
  • hey - contact an admin through the bot
  • credits - show credits

Setup

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

Configuration

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

Other notes

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

Credits

Used libraries:

Data sources: