Skip to content

My personal Telegram bot made in Python. It has several features and it's based on Pyrogram.

License

Notifications You must be signed in to change notification settings

MasterCruelty/robbot

Repository files navigation

Maintainability Rating Quality Gate Pass Lines of Code License image image CodeSize image image image Image GitHub commits since latest release (by date) image

Robbot

IT/ENG

This Telegram bot has the same structure of this project which is an userbot I made for several features I needed.
So this bot has some commands in common with that userbot but also other new commands and obviously there aren't those commands that a bot can't execute but a userbot can.
So if you're interested you can also visit that repository.


Feel free to contribute and improve the project.
See more details on How to contribute here.

After the Italian section you will find an english version of the README. In doc folder you will find a bit of documentation of RobBot.

[IT]

Come impostare

Per un corretto funzionamento è necessario compilare a dovere il file config.json. Quindi è necessario essere in possesso dei seguenti dati:

  • Api keys di Telegram: api_id e api_hash. Puoi generarle da qui
  • Bot token: bot_token. Puoi generarlo da qui
  • Api url atm se si vogliono usare le loro api: api_url , api_get e cookie. (Non essendo pubbliche non le condividerò)
  • Api key di OpenWeatherMap: api_weather. Puoi generare la tua key dal sito principale di OpenWeatherMap
  • Api di OpenAI: api_openai. Puoi generare la tua key dal sito principale di OpenAI
  • I dati telegram dell'amministratore del bot: id_super_admin.
  • Il percorso dove si trova il file .db: path_db.
  • Nome della sessione: session_name.
  • I nomi dei comandi utente, admin e superadmin: user_commands, admin_commands e super_admin_commands.

I dati del super admin servono a colui che potrà usare le funzioni di interazione con il database e altre funzioni particolari. I nomi dei comandi da inserire nel config.json possono essere ricopiati dal codice oppure possono essere modificati sul codice e poi ricopiati nel file json.

Se siete su un'ambiente totalmente a linea di comando e vi accedete in ssh, consiglio il seguente comando per avviare il bot:

python3 app.py 2>&1 > /dev/tty1 &

Come funzionano i comandi utente del bot

Il funzionamento dei comandi utente è spiegato all'interno del file help.json. Si tratta del file che viene usato dal bot per rispondere al comando /helprob <nome comando>. Le spiegazioni sono in Italiano, ma volendo si possono tradurre in qualsiasi lingua sostituendo i campi della struttura dati oppure addirittura renderlo multilingua, ma in quel caso c'è da sviluppare la componente che rende possibile il cambio di lingua.

Come funzionano i comandi admin e super

  • registrare un nuovo utente: /setrobuser <id_utente>
  • registrare un nuovo admin: /setrobadmin <id_utente>
  • cancellare un utente: /delrobuser <id_utente>
  • revocare i privilegi admin: /delrobadmin <id_utente> (l'utente sarà comunque ancora tra i registrati ma senza i poteri admin)
  • mostrare tutti gli utenti registrati: /listrobuser
  • mostrare il numero di utenti registrati: /allrobuser
  • verificare se il bot è online: /pingrob
  • registrare un nuovo gruppo come unico autorizzato a ricevere un certo comando: /setgroup <id_gruppo>
  • cancellare un gruppo salvato: /delgroup <id_gruppo>
  • mostrare tutti i gruppi salvati: /listgroup
  • modificare un valore nelle statistiche di un utente per un certo comando: /updatestat <id_utente> 'comando' <nuovo_valore>
  • cancellare un comando dalle statistiche di un utente: /delstat <id_utente> 'comando'
  • Aggiornare i dati Telegram di un utente(nome e username): /updaterobuser <id_utente> (oppure dando lo username)
  • Aggiornare il credito di un utente per l'utilizzo di openai: /amount <id_utente>
  • Visualizzare l'elenco degli utenti che hanno del credito di utilizzo per openai: /allamounts
  • Riavviare il bot direttamente da Telegram senza passare dalla shell: /restart
  • Inviare un messaggio a un utente registrato: /say ; 'messaggio'

Dipendenze

  • Pyrogram
  • tgcrypto
  • peewee
  • utils_config
  • geopy
  • bs4
  • wikipedia
  • pandas
  • matplotlib
  • openai
  • urbandictionary
  • pdf2image
  • pytube
  • flightradar24
  • FlightRadarAPI
  • pokebase
  • wikipediaapi

Progetti esterni usati

[ENG]

How to setup

The correct way to setup this bot is to compile the file config.json. So it's necessary to have these data:

  • Telegram api keys: api_id e api_hash. You can generate them here
  • Telegram bot token: bot_token. You can generate it from here
  • Atm api url if you wanna use their api: api_url , api_get and cookie. (The api are not public so I won't share them here)
  • OpenWeatherMap api key: api_weather. You can generate your key from the OpenWeatherMap website.
  • OpenAI api key: api_openai. You can generate your key from the OpenAI website.
  • Telegram data of the owner of the bot: id_super_admin.
  • The path where is the .db file: path_db.
  • The session name: session_name.
  • Name of user commands, admin commands and super admin commands: user_commands, admin_commands e super_admin_commands.

Data of super admin is needed because he's the only one who can use db functions and other special functions. Name of commands to put inside config.json can be copied from source code or renamed inside source code and then copied in json file.

How the user bot's commands works

The features of the user commands are explained inside help.json. It is the file which is used by the bot to reply at /helprob <command name>. This json file is only in Italian, but you can translate it in every languages by changing the correct fields with your translations or even making the bot multi-language but in that case you have to develop the component for change the language runtime.

If you're in a command-line env and you access with ssh, I suggest the following command to start the bot:

python3 app.py 2>&1 > /dev/tty1 &

How the admin/super commands works

  • register a new user: /setrobuser <id_user>
  • register a new admin: /setrobadmin <id_user>
  • delete a user: /delrobuser <id_user>
  • delete an admin: /delrobadmin <id_user> (it will just revoke the admin power, it doesn't delete the user)
  • How to list all user registered: /listrobuser
  • How to show ho many users are registered: /allrobuser
  • check if the bot is online: /pingrob
  • Save a new group to make it the only one authorized to receive a specific command: /setgroup <id_group>
  • Delete a saved group: /delgroup <id_group>
  • Show all saved groups: /listgroup
  • Update a value in a user's stat for a specific command: /updatestat <id_user> 'command' <new_value>
  • Delete a command from a user's stat: /delstat <id_user> 'command'
  • Update user's Telergam data(name and username): /updaterobuser <id_user> (or giving username)
  • Update the user's credit for openai usage: /amount <id_user>
  • Show all user and their openai credit: /allamounts
  • Restarting the bot directly in Telegram without manually doing in shell: /restart
  • Sending a message to a registered user: /say <id_user> ; 'message'

Dependencies

  • Pyrogram
  • tgcrypto
  • peewee
  • utils_config
  • geopy
  • bs4
  • wikipedia
  • pandas
  • matplotlib
  • openai
  • urbandictionary
  • pdf2image
  • pytube
  • flightradar24
  • FlightRadarAPI
  • pokebase
  • wikipediaapi

External projects used