Skip to content

Commit 8f20490

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 5be52fb + 91a72b4 commit 8f20490

6 files changed

Lines changed: 211 additions & 231 deletions

File tree

README.md

Lines changed: 100 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,199 +1,178 @@
1-
# tgbot
1+
# PythonItaliaTGbot
22

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

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'è?
76

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

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
1310

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

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
2014

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

23-
## IMPORTANT NOTICE:
17+
#### Installazione e configurazione di postgres
18+
- Installa postgres:
2419

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+
```
2829

29-
## Starting the bot.
30+
- Crea un nuovo database utente (cambia USER con il nome dell'utente):
3031

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

33-
`python3 -m tg_bot`
37+
- Crea una nuova tabella nel db:
3438

35-
## Setting up the bot (Read this before trying to use!):
39+
```
40+
createdb -O USER YDB_NAME
41+
```
42+
- In fine
3643

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+
```
3952

40-
### Configuration
4153

42-
There are two possible ways of configuring your bot: a config.py file, or ENV variables.
54+
## Configurazione
4355

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

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

52-
An example `config.py` file could be:
61+
Un esempio di config.py potrebbe essere:
5362

5463
```
5564
from tg_bot.sample_config import Config
5665
5766
5867
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
6170
API_KEY = "your bot api key" # my api key, as provided by the botfather
6271
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
6473
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.
6675
LOAD = []
6776
NO_LOAD = ['translation']
6877
```
6978

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:
7480

75-
- `TOKEN`: Your bot token, as a string.
76-
- `OWNER_ID`: An integer of consisting of your owner ID
77-
- `OWNER_USERNAME`: Your username
7881

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

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
10184

102-
### Python dependencies
85+
TOKEN: Token del bot, come stringa.
10386

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

106-
`pip3 install -r requirements.txt`.
89+
OWNER_USERNAME: Il tuo username
10790

108-
This will install all necessary python packages.
91+
DATABASE_URL: URI del db
10992

110-
### Database
93+
MESSAGE_DUMP: opzionale: chat in cui sono salvate le risposte del bot dove non possono essere cancellate
11194

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
11496

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
11698

117-
- install postgresql:
99+
WEBHOOK: Impostarlo a ANYTHING abiliterà i webhooks nei messaggi env
118100

119-
`sudo apt-get update && sudo apt-get install postgresql`
101+
URL: URL del webhook (richiesto solo se abilitata la modalità webhook)
120102

121-
- change to the postgres user:
103+
SUDO_USERS: Lista separata da spazi di ids di amministratori del bot
122104

123-
`sudo su - postgres`
105+
SUPPORT_USERS: Lista separata da spazi di ids di utenti-supporter (possono gban/ungban, e basta)
124106

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
126108

127-
`createuser -P -s -e YOUR_USER`
109+
DONATION_LINK: Opzionale: Link per le donazioni
128110

129-
This will be followed by you needing to input your password.
111+
CERT_PATH: Path del certificato webhooks
130112

131-
- create a new database table:
113+
PORT: Porta usata per connettersi al tuo servizio webhooks
132114

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
134116

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
136118

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

139-
`psql YOUR_DB_NAME -h YOUR_HOST YOUR_USER`
121+
BAN_STICKER: Sticker da usare quando viene bannato un utente.
140122

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 /.
143124

144-
You should now be able to build your database URI. This will be:
145125

146-
`sqldbtype://username:pw@hostname:port/db_name`
147126

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
150128

151-
## Modules
129+
Installa le dependency con questo comando:
152130

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+
```
157134

158-
If `LOAD` is an empty list, all modules in `modules/` will be selected for loading by default.
135+
## Moduli
159136

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
161138

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

164-
### Creating your own modules.
141+
Nota: NO_LOAD è prioritario rispetto a LOAD
165142

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
167144

168-
All that is needed is that your .py file be in the modules folder.
145+
#### Requisiti
146+
- docker
147+
- docker-compose
169148

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+
```
171155

172-
`from tg_bot import dispatcher`.
156+
## Costruito con
173157

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
175161

176-
`dispatcher.add_handler()`.
162+
## Come contribuire
177163

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

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
185168

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

189-
### Running dev with docker
171+
## Autori
190172

191-
#### Requirements
173+
Controlla la lista di [contributors](https://github.com/Kavuti/python-italy-telegram-bot/graphs/contributors) che hanno reso questo progetto grande.
192174

193-
- docker
194-
- docker-compose
175+
## License
195176

196-
#### Up & Running
177+
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
197178

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

Comments
 (0)