|
1 | | -# tgbot |
| 1 | +# PythonItaliaTGbot |
2 | 2 |
|
3 | | -A modular telegram Python bot running on python3 with an sqlalchemy database. |
| 3 | +Bot principale per il gruppo Telegram di [PythonItalia](https://t.me/python_ita). |
4 | 4 |
|
5 | | -Originally a simple group management bot with multiple admin features, it has evolved into becoming a basis for modular |
6 | | -bots aiming to provide simple plugin expansion via a simple drag and drop. |
| 5 | +## Che cos'è? |
7 | 6 |
|
8 | | -Can be found on telegram as [Marie](https://t.me/BanhammerMarie_bot). |
| 7 | +Questo bot è un fork della versione base di tgBot (ex Marie). Lo sviluppo orizzontale del bot ha permesso di aggiungere funzionalità e risolvere bug presenti nel codice sorgente originale. |
9 | 8 |
|
10 | | -For questions regarding creating your own bot, please head to [this chat](https://t.me/MarieOT) where you'll find a |
11 | | -group of volunteers to help. We'll also help when a database schema changes, and some table column needs to be |
12 | | -modified/added (this info can also be found in the commit messages) |
| 9 | +### Il deploy |
13 | 10 |
|
14 | | -Join the [news channel](https://t.me/MarieNews) if you just want to stay in the loop about new features or |
15 | | -announcements. |
| 11 | +Il deploy del bot può essere effettuato su Heroku (settando le variabili di ambiente) che su una VPS dedicata (preferibilmente con kernel linux > 2.6.13). |
16 | 12 |
|
17 | | -Marie and I can also be found moderating the [marie support group](https://t.me/MarieSupport) aimed at providing help |
18 | | -setting up Marie in your chats (_not_ for bot clones). |
19 | | -Feel free to join to report bugs, and stay in the loop on the status of the bot development. |
| 13 | +### Configurazione del db |
20 | 14 |
|
21 | | -Note to maintainers that all schema changes will be found in the commit messages, and its their responsibility to read any new commits. |
| 15 | +Il primo step necessario è la configurazione del database postgres. |
22 | 16 |
|
23 | | -## IMPORTANT NOTICE: |
| 17 | +#### Installazione e configurazione di postgres |
| 18 | +- Installa postgres: |
24 | 19 |
|
25 | | -This project is no longer under active maintenance. Occasional bug fixes may be released, but no new features are scheduled to be added. |
26 | | -Users of [Marie](https://t.me/BanhammerMarie_bot) are encouraged to migrate to [Rose](https://t.me/MissRose_bot), which |
27 | | -is the improved version of this project, written in goloang, with scalability in mind. |
| 20 | +``` |
| 21 | +sudo apt-get update && sudo apt-get install postgresql |
| 22 | +``` |
| 23 | + |
| 24 | +- Cambia l'utente postgres: |
| 25 | + |
| 26 | +``` |
| 27 | +sudo su - postgres |
| 28 | +``` |
28 | 29 |
|
29 | | -## Starting the bot. |
| 30 | +- Crea un nuovo database utente (cambia USER con il nome dell'utente): |
30 | 31 |
|
31 | | -Once you've setup your database and your configuration (see below) is complete, simply run: |
| 32 | +``` |
| 33 | +createuser -P -s -e USER |
| 34 | +``` |
| 35 | +Ti verrà chiesto di inserire una password. |
32 | 36 |
|
33 | | -`python3 -m tg_bot` |
| 37 | +- Crea una nuova tabella nel db: |
34 | 38 |
|
35 | | -## Setting up the bot (Read this before trying to use!): |
| 39 | +``` |
| 40 | +createdb -O USER YDB_NAME |
| 41 | +``` |
| 42 | +- In fine |
36 | 43 |
|
37 | | -Please make sure to use python3.6, as I cannot guarantee everything will work as expected on older python versions! |
38 | | -This is because markdown parsing is done by iterating through a dict, which are ordered by default in 3.6. |
| 44 | +``` |
| 45 | +psql DB_NAME -h YOUR_HOST USER |
| 46 | +``` |
| 47 | +A questo punto sarai in grado di connetterti al db via terminal. Di default YOUR_HOST dovrebbe essere 0.0.0.0:5432. |
| 48 | +Il database-uri sarà quindi: |
| 49 | +``` |
| 50 | +postgres://username:pw@hostname:port/db_name |
| 51 | +``` |
39 | 52 |
|
40 | | -### Configuration |
41 | 53 |
|
42 | | -There are two possible ways of configuring your bot: a config.py file, or ENV variables. |
| 54 | +## Configurazione |
43 | 55 |
|
44 | | -The prefered version is to use a `config.py` file, as it makes it easier to see all your settings grouped together. |
45 | | -This file should be placed in your `tg_bot` folder, alongside the `__main__.py` file . |
46 | | -This is where your bot token will be loaded from, as well as your database URI (if you're using a database), and most of |
47 | | -your other settings. |
| 56 | +Esistono due modi per configurare il bot: modificando il file config.py oppure impostando delle variabili d'ambiente. |
48 | 57 |
|
49 | | -It is recommended to import sample_config and extend the Config class, as this will ensure your config contains all |
50 | | -defaults set in the sample_config, hence making it easier to upgrade. |
| 58 | +Il metodo migliore è l'uso del file config.py perchè è più semplice rivedere tutte le impostazioni in un singolo file. |
| 59 | +Il metodo predefinito per creare il file config.py è estendere la classe di sample_config. |
51 | 60 |
|
52 | | -An example `config.py` file could be: |
| 61 | +Un esempio di config.py potrebbe essere: |
53 | 62 |
|
54 | 63 | ``` |
55 | 64 | from tg_bot.sample_config import Config |
56 | 65 |
|
57 | 66 |
|
58 | 67 | class Development(Config): |
59 | | - OWNER_ID = 254318997 # my telegram ID |
60 | | - OWNER_USERNAME = "SonOfLars" # my telegram username |
| 68 | + OWNER_ID = 00000000 # my telegram ID |
| 69 | + OWNER_USERNAME = "########" # my telegram username |
61 | 70 | API_KEY = "your bot api key" # my api key, as provided by the botfather |
62 | 71 | SQLALCHEMY_DATABASE_URI = 'postgresql://username:password@localhost:5432/database' # sample db credentials |
63 | | - MESSAGE_DUMP = '-1234567890' # some group chat that your bot is a member of |
| 72 | + MESSAGE_DUMP = '00000000' # some group chat that your bot is a member of |
64 | 73 | USE_MESSAGE_DUMP = True |
65 | | - SUDO_USERS = [18673980, 83489514] # List of id's for users which have sudo access to the bot. |
| 74 | + SUDO_USERS = [0000000, 000000] # List of id's for users which have sudo access to the bot. |
66 | 75 | LOAD = [] |
67 | 76 | NO_LOAD = ['translation'] |
68 | 77 | ``` |
69 | 78 |
|
70 | | -If you can't have a config.py file (EG on heroku), it is also possible to use environment variables. |
71 | | -The following env variables are supported: |
72 | | - |
73 | | -- `ENV`: Setting this to ANYTHING will enable env variables |
| 79 | +Nel caso in cui tu voglia deployare il bot su heroku dovrai impostare le ENV. Sono supportate le seguenti variabili: |
74 | 80 |
|
75 | | -- `TOKEN`: Your bot token, as a string. |
76 | | -- `OWNER_ID`: An integer of consisting of your owner ID |
77 | | -- `OWNER_USERNAME`: Your username |
78 | 81 |
|
79 | | -- `DATABASE_URL`: Your database URL |
80 | | -- `MESSAGE_DUMP`: optional: a chat where your replied saved messages are stored, to stop people deleting their old |
81 | | -- `LOAD`: Space separated list of modules you would like to load |
82 | | -- `NO_LOAD`: Space separated list of modules you would like NOT to load |
83 | | -- `WEBHOOK`: Setting this to ANYTHING will enable webhooks when in env mode |
84 | | - messages |
85 | | -- `URL`: The URL your webhook should connect to (only needed for webhook mode) |
86 | 82 |
|
87 | | -- `SUDO_USERS`: A space separated list of user_ids which should be considered sudo users |
88 | | -- `SUPPORT_USERS`: A space separated list of user_ids which should be considered support users (can gban/ungban, |
89 | | - nothing else) |
90 | | -- `WHITELIST_USERS`: A space separated list of user_ids which should be considered whitelisted - they can't be banned. |
91 | | -- `DONATION_LINK`: Optional: link where you would like to receive donations. |
92 | | -- `CERT_PATH`: Path to your webhook certificate |
93 | | -- `PORT`: Port to use for your webhooks |
94 | | -- `DEL_CMDS`: Whether to delete commands from users which don't have rights to use that command |
95 | | -- `STRICT_GBAN`: Enforce gbans across new groups as well as old groups. When a gbanned user talks, he will be banned. |
96 | | -- `WORKERS`: Number of threads to use. 8 is the recommended (and default) amount, but your experience may vary. |
97 | | - **Note** that going crazy with more threads wont necessarily speed up your bot, given the large amount of sql data |
98 | | - accesses, and the way python asynchronous calls work. |
99 | | -- `BAN_STICKER`: Which sticker to use when banning people. |
100 | | -- `ALLOW_EXCL`: Whether to allow using exclamation marks ! for commands as well as /. |
| 83 | + ENV: Setting this to ANYTHING will enable env variables |
101 | 84 |
|
102 | | -### Python dependencies |
| 85 | + TOKEN: Token del bot, come stringa. |
103 | 86 |
|
104 | | -Install the necessary python dependencies by moving to the project directory and running: |
| 87 | + OWNER_ID: Numero intero che identifica il proprietario del bot (id di Telegram) |
105 | 88 |
|
106 | | -`pip3 install -r requirements.txt`. |
| 89 | + OWNER_USERNAME: Il tuo username |
107 | 90 |
|
108 | | -This will install all necessary python packages. |
| 91 | + DATABASE_URL: URI del db |
109 | 92 |
|
110 | | -### Database |
| 93 | + MESSAGE_DUMP: opzionale: chat in cui sono salvate le risposte del bot dove non possono essere cancellate |
111 | 94 |
|
112 | | -If you wish to use a database-dependent module (eg: locks, notes, userinfo, users, filters, welcomes), |
113 | | -you'll need to have a database installed on your system. I use postgres, so I recommend using it for optimal compatibility. |
| 95 | + LOAD: Lista separata da spazi di moduli che vuoi abilitare |
114 | 96 |
|
115 | | -In the case of postgres, this is how you would set up a the database on a debian/ubuntu system. Other distributions may vary. |
| 97 | + NO_LOAD: Lista separata da spazi di moduli che NON vuoi abilitare |
116 | 98 |
|
117 | | -- install postgresql: |
| 99 | + WEBHOOK: Impostarlo a ANYTHING abiliterà i webhooks nei messaggi env |
118 | 100 |
|
119 | | -`sudo apt-get update && sudo apt-get install postgresql` |
| 101 | + URL: URL del webhook (richiesto solo se abilitata la modalità webhook) |
120 | 102 |
|
121 | | -- change to the postgres user: |
| 103 | + SUDO_USERS: Lista separata da spazi di ids di amministratori del bot |
122 | 104 |
|
123 | | -`sudo su - postgres` |
| 105 | + SUPPORT_USERS: Lista separata da spazi di ids di utenti-supporter (possono gban/ungban, e basta) |
124 | 106 |
|
125 | | -- create a new database user (change YOUR_USER appropriately): |
| 107 | + WHITELIST_USERS: Lista separata da spazi di ids di utenti che non possono essere bannati |
126 | 108 |
|
127 | | -`createuser -P -s -e YOUR_USER` |
| 109 | + DONATION_LINK: Opzionale: Link per le donazioni |
128 | 110 |
|
129 | | -This will be followed by you needing to input your password. |
| 111 | + CERT_PATH: Path del certificato webhooks |
130 | 112 |
|
131 | | -- create a new database table: |
| 113 | + PORT: Porta usata per connettersi al tuo servizio webhooks |
132 | 114 |
|
133 | | -`createdb -O YOUR_USER YOUR_DB_NAME` |
| 115 | + DEL_CMDS: Se cancellare i comandi dagli utenti che non hanno i diritti per usare quel comando |
134 | 116 |
|
135 | | -Change YOUR_USER and YOUR_DB_NAME appropriately. |
| 117 | + STRICT_GBAN: Imponi gban su nuovi gruppi e vecchi gruppi. Quando un utente gbanned parla, sarà bannato |
136 | 118 |
|
137 | | -- finally: |
| 119 | + WORKERS: Numero di threads da usare. 8 è raccomandato (e numero di default). Nota che aumentare questo numero non porterà necessariamente dei benefici alla velocità del bot. |
138 | 120 |
|
139 | | -`psql YOUR_DB_NAME -h YOUR_HOST YOUR_USER` |
| 121 | + BAN_STICKER: Sticker da usare quando viene bannato un utente. |
140 | 122 |
|
141 | | -This will allow you to connect to your database via your terminal. |
142 | | -By default, YOUR_HOST should be 0.0.0.0:5432. |
| 123 | + ALLOW_EXCL: Se consentire l'utilizzo di punti esclamativi ! per i comandi e /. |
143 | 124 |
|
144 | | -You should now be able to build your database URI. This will be: |
145 | 125 |
|
146 | | -`sqldbtype://username:pw@hostname:port/db_name` |
147 | 126 |
|
148 | | -Replace sqldbtype with whichever db youre using (eg postgres, mysql, sqllite, etc) |
149 | | -repeat for your username, password, hostname (localhost?), port (5432?), and db name. |
| 127 | +### Dependency |
150 | 128 |
|
151 | | -## Modules |
| 129 | +Installa le dependency con questo comando: |
152 | 130 |
|
153 | | -### Setting load order. |
154 | | - |
155 | | -The module load order can be changed via the `LOAD` and `NO_LOAD` configuration settings. |
156 | | -These should both represent lists. |
| 131 | +``` |
| 132 | +pip3 install -r requirements.txt |
| 133 | +``` |
157 | 134 |
|
158 | | -If `LOAD` is an empty list, all modules in `modules/` will be selected for loading by default. |
| 135 | +## Moduli |
159 | 136 |
|
160 | | -If `NO_LOAD` is not present, or is an empty list, all modules selected for loading will be loaded. |
| 137 | +#### Imposta l'ordine di caricamento dei moduli |
161 | 138 |
|
162 | | -If a module is in both `LOAD` and `NO_LOAD`, the module will not be loaded - `NO_LOAD` takes priority. |
| 139 | +L'ordine di caricamento in memoria dei moduli può essere opportunamente modificato tramite l'uso di LOAD e NO_LOAD. |
163 | 140 |
|
164 | | -### Creating your own modules. |
| 141 | +Nota: NO_LOAD è prioritario rispetto a LOAD |
165 | 142 |
|
166 | | -Creating a module has been simplified as much as possible - but do not hesitate to suggest further simplification. |
| 143 | +## Avviare il bot con docker |
167 | 144 |
|
168 | | -All that is needed is that your .py file be in the modules folder. |
| 145 | +#### Requisiti |
| 146 | +- docker |
| 147 | +- docker-compose |
169 | 148 |
|
170 | | -To add commands, make sure to import the dispatcher via |
| 149 | +#### Avvio |
| 150 | +- Crea un file .env usando docker/dev/config.sample come template e salvandola in docker/dev/ |
| 151 | +- Assicurati di essere nella root del progetto e inserisci il seguente comando: |
| 152 | +``` |
| 153 | +docker-compose -f docker/dev/docker-compose.yml up -d |
| 154 | +``` |
171 | 155 |
|
172 | | -`from tg_bot import dispatcher`. |
| 156 | +## Costruito con |
173 | 157 |
|
174 | | -You can then add commands using the usual |
| 158 | +* [tgbot](https://github.com/PaulSonOfLars/tgbot) - Bot modulare scritto in Python3 |
| 159 | +* [Trevis CI](https://travis-ci.com) - Deploy in production |
| 160 | +* [Docker](https://www.docker.com/) - Usato per sviluppare il bot in ambiente dev |
175 | 161 |
|
176 | | -`dispatcher.add_handler()`. |
| 162 | +## Come contribuire |
177 | 163 |
|
178 | | -Assigning the `__help__` variable to a string describing this modules' available |
179 | | -commands will allow the bot to load it and add the documentation for |
180 | | -your module to the `/help` command. Setting the `__mod_name__` variable will also allow you to use a nicer, user |
181 | | -friendly name for a module. |
| 164 | +Per favore leggi [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) per avere dettagli sulle regole |
| 165 | +per contribuire e come effettuare una pull-request. |
182 | 166 |
|
183 | | -The `__migrate__()` function is used for migrating chats - when a chat is upgraded to a supergroup, the ID changes, so |
184 | | -it is necessary to migrate it in the db. |
| 167 | +## Versioning |
185 | 168 |
|
186 | | -The `__stats__()` function is for retrieving module statistics, eg number of users, number of chats. This is accessed |
187 | | -through the `/stats` command, which is only available to the bot owner. |
| 169 | +Noi usiamo [SemVer](http://semver.org/) per il versioning, sincronizzato con i tag in production di GH. |
188 | 170 |
|
189 | | -### Running dev with docker |
| 171 | +## Autori |
190 | 172 |
|
191 | | -#### Requirements |
| 173 | +Controlla la lista di [contributors](https://github.com/Kavuti/python-italy-telegram-bot/graphs/contributors) che hanno reso questo progetto grande. |
192 | 174 |
|
193 | | -- docker |
194 | | -- docker-compose |
| 175 | +## License |
195 | 176 |
|
196 | | -#### Up & Running |
| 177 | +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details |
197 | 178 |
|
198 | | -- Create .env file by using docker/dev/config.sample as template and save it into docker/dev/ |
199 | | -- Be sure to be at project root directory and run `docker-compose -f docker/dev/docker-compose.yml up -d` |
0 commit comments