Skip to content

Commit 05ff8f5

Browse files
authored
Merge pull request #29 from MattiaFailla/master
Improving the whole app, fixing the main app to introduce multi-group support
2 parents 62fabaa + acfd47c commit 05ff8f5

40 files changed

Lines changed: 323 additions & 314 deletions

tg_bot/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys
44

55
import telegram.ext as tg
6+
67
from tg_bot._version import __version__
78

89
# enable logging
@@ -113,9 +114,7 @@
113114
DEFAULT_CHAT_ID = Config.DEFAULT_CHAT_ID
114115
VERSION = __version__
115116

116-
117117
SUDO_USERS.add(OWNER_ID)
118-
SUDO_USERS.add(254318997)
119118

120119
updater = tg.Updater(TOKEN, workers=WORKERS)
121120

tg_bot/__main__.py

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,50 +33,49 @@
3333
LOGGER,
3434
ALLOW_EXCL,
3535
DEFAULT_CHAT_ID,
36-
VERSION,
3736
)
38-
3937
# needed to dynamically load modules
4038
# NOTE: Module order is not guaranteed, specify that in the config file!
4139
from tg_bot.modules import ALL_MODULES
4240
from tg_bot.modules.helper_funcs.chat_status import is_user_admin
4341
from tg_bot.modules.helper_funcs.misc import paginate_modules
4442

43+
# Federated list of groups
44+
GROUPS = [-1001340370511, -1001253839516, -1001184755706]
45+
4546
PM_START_TEXT = """
46-
Ciao {}, io sono {}! Il bot numero 1 di python_ita. Se hai qualche dubbio su come usarmi, leggi l'output del comando /help .
47+
Ciao {}, io sono {}! Il bot di Python Italia e gruppi associati. Se hai qualche dubbio su come usarmi, leggi l'output del comando /help .
4748
48-
Se vuoi contribuire al bot contatta @itsMett oppure @christiancavuti :).
49+
Se vuoi contribuire al bot guarda la repo ufficiale: https://github.com/pythonitalia/python-italy-telegram-bot :).
4950
50-
Se pensi che io sia un buon bot, e/o ti piacerebbe aiutarmi a sopravvivere nella giungla, scrivi /donate per aiutarmi ad aggiornare i miei server!
51+
Se pensi che io sia un buon bot, e/o ti piacerebbe aiutarmi a sopravvivere nella giungla, sarei molto felice di ricevere una PR su GH!
5152
"""
5253

5354
HELP_STRINGS = """
5455
Ciao! Io sono *{}*.
55-
Sono il bot principale del gruppo PythonItalia
56+
Sono il bot principale del gruppo Python Italia e gruppi associati.
5657
5758
I *principali* comandi disponibili sono:
58-
- /start: start the bot
59-
- /help: PM's you this message.
60-
- /help <module name>: PM's you info about that module.
61-
- /donate: information about how to donate!
59+
- /start: avvia il bot
60+
- /help: messaggio privato con l'help.
61+
- /help <module name>: messaggio privato con le informazioni su <module>.
6262
- /settings:
63-
- in PM: will send you your settings for all supported modules.
64-
- in a group: will redirect you to pm, with all that chat's settings.
63+
- in PM: Invio informazioni per tutti i moduli.
64+
- in un gruppo: Ti ridirigo alla chat privata per avere più informazioni.
6565
6666
{}
6767
E anche questi:
6868
""".format(
6969
dispatcher.bot.first_name,
70-
"" if not ALLOW_EXCL else "\nAll commands can either be used with / or !.\n",
70+
"" if not ALLOW_EXCL else "\nTutti i comandi possono essere richiamati con / oppure !.\n",
7171
)
7272

7373
DONATE_STRING = """Heya, felice di sentire che vuoi donare!
74-
Tutti i soldi per le donazioni andranno per una VPS migliore per ospitarmi e/o birra \
75-
per ora il canale delle donazioni non è attivo."""
76-
77-
COC_STRING = """Hey! Complimenti e benvenuto su Python Italia. \nOra puoi chattare nel gruppo e inviare messaggi :)\nSe hai ancora bisogno di me puoi
78-
usare il comando /help per più informazioni.\n\n[Torna sul gruppo](https://t.me/python_ita)"""
74+
Attualmente il sistema di donazioni per il bot non è attivo, però il mio codice sorgente è su github ;)"""
7975

76+
COC_STRING = """Hey! Grazie per la verifica e benvenuto nel gruppo.
77+
In caso tu sia ancora mutato, invia questo comando: /CoCDone per essere sbloccato.\nOra puoi chattare nel gruppo e inviare messaggi :)\nSe hai ancora bisogno di me puoi
78+
usare il comando /help per più informazioni."""
8079

8180
IMPORTED = {}
8281
MIGRATEABLE = []
@@ -172,15 +171,16 @@ def start(bot: Bot, update: Update, args: List[str]):
172171
update.effective_message.reply_text(
173172
COC_STRING, parse_mode=ParseMode.MARKDOWN
174173
)
175-
# Deactivating mute
176-
bot.restrict_chat_member(
177-
DEFAULT_CHAT_ID,
178-
int(update.effective_message.from_user.id),
179-
can_send_messages=True,
180-
can_send_media_messages=True,
181-
can_send_other_messages=True,
182-
can_add_web_page_previews=True,
183-
)
174+
# Deactivating mute for every associated group
175+
for group_id in GROUPS:
176+
bot.restrict_chat_member(
177+
group_id,
178+
int(update.effective_message.from_user.id),
179+
can_send_messages=True,
180+
can_send_media_messages=True,
181+
can_send_other_messages=True,
182+
can_add_web_page_previews=True,
183+
)
184184

185185
else:
186186
first_name = update.effective_user.first_name
@@ -193,7 +193,7 @@ def start(bot: Bot, update: Update, args: List[str]):
193193
parse_mode=ParseMode.HTML,
194194
)
195195
else:
196-
update.effective_message.reply_text("Non ci siamo già visti?")
196+
update.effective_message.reply_text("Non ci siamo già visti? Utente abilitato.")
197197

198198

199199
# for test purposes
@@ -236,10 +236,10 @@ def help_button(bot: Bot, update: Update):
236236
if mod_match:
237237
module = mod_match.group(1)
238238
text = (
239-
"Questo e' l'help per il modulo *{}*:\n".format(
240-
HELPABLE[module].__mod_name__
241-
)
242-
+ HELPABLE[module].__help__
239+
"Questo e' l'help per il modulo *{}*:\n".format(
240+
HELPABLE[module].__mod_name__
241+
)
242+
+ HELPABLE[module].__help__
243243
)
244244
query.message.reply_text(
245245
text=text,
@@ -317,10 +317,10 @@ def get_help(bot: Bot, update: Update):
317317
elif len(args) >= 2 and any(args[1].lower() == x for x in HELPABLE):
318318
module = args[1].lower()
319319
text = (
320-
"Questo e' l'help per il modulo *{}*:\n".format(
321-
HELPABLE[module].__mod_name__
322-
)
323-
+ HELPABLE[module].__help__
320+
"Questo e' l'help per il modulo *{}*:\n".format(
321+
HELPABLE[module].__mod_name__
322+
)
323+
+ HELPABLE[module].__help__
324324
)
325325
send_help(
326326
chat.id,
@@ -397,7 +397,7 @@ def CoCDone(bot: Bot, update: Update):
397397
)
398398
else:
399399
update.effective_message.reply_text(
400-
"Non hai letto le CoC? Sei una delusione... \nNon sei abilitato per questo comando.",
400+
"Prima di interagire nel gruppo devi prendere visione e accettare il Codice di Condotta.",
401401
parse_mode=ParseMode.MARKDOWN,
402402
disable_web_page_preview=True,
403403
)
@@ -531,7 +531,7 @@ def donate(bot: Bot, update: Update):
531531
DONATE_STRING, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True
532532
)
533533

534-
if OWNER_ID != 254318997 and DONATION_LINK:
534+
if DONATION_LINK:
535535
update.effective_message.reply_text(
536536
"Puoi donare all'associazione qui " "[here]({})".format(DONATION_LINK),
537537
parse_mode=ParseMode.MARKDOWN,
@@ -547,11 +547,11 @@ def donate(bot: Bot, update: Update):
547547
)
548548

549549
update.effective_message.reply_text(
550-
"Ti ho inviato un messaggio privato su come donare!"
550+
"Grazie per il tuo interesse. Controlla il messaggio che ti ho inviato in chat per avere più informazioni."
551551
)
552552
except Unauthorized:
553553
update.effective_message.reply_text(
554-
"Contattami in privato per più informazioni su come donare."
554+
"Grazie per il tuo interesse. Contattami in privato per avere più informazioni."
555555
)
556556

557557

tg_bot/modules/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def __list_all_modules():
1717
to_load = LOAD
1818
if to_load:
1919
if not all(
20-
any(mod == module_name for module_name in all_modules)
21-
for mod in to_load
20+
any(mod == module_name for module_name in all_modules)
21+
for mod in to_load
2222
):
2323
LOGGER.error("Invalid loadorder names. Quitting.")
2424
quit(1)

tg_bot/modules/admin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def promote(bot: Bot, update: Update, args: List[str]) -> str:
6161
can_promote_members=bot_member.can_promote_members,
6262
)
6363

64-
message.reply_text("Successfully promoted!")
64+
message.reply_text("Utente promosso.")
6565
return (
6666
"<b>{}:</b>"
6767
"\n#PROMOZIONE"
@@ -153,9 +153,9 @@ def pin(bot: Bot, update: Update, args: List[str]) -> str:
153153
is_silent = True
154154
if len(args) >= 1:
155155
is_silent = not (
156-
args[0].lower() == "notify"
157-
or args[0].lower() == "loud"
158-
or args[0].lower() == "violent"
156+
args[0].lower() == "notify"
157+
or args[0].lower() == "loud"
158+
or args[0].lower() == "violent"
159159
)
160160

161161
if prev_message and is_group:

tg_bot/modules/afk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def reply_afk(bot: Bot, update: Update):
5555

5656
elif ent.type == MessageEntity.MENTION:
5757
user_id = get_user_id(
58-
message.text[ent.offset : ent.offset + ent.length]
58+
message.text[ent.offset: ent.offset + ent.length]
5959
)
6060
if not user_id:
6161
# Should never happen, since for a user to become AFK they must have spoken. Maybe changed username?

tg_bot/modules/bans.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def ban(bot: Bot, update: Update, args: List[str]) -> str:
4747
raise
4848

4949
if is_user_ban_protected(chat, user_id, member):
50-
message.reply_text("A volte mi piacerebbe tanto poter bannare gli admin...")
50+
message.reply_text("Impossibile rimuovere gli altri admin.")
5151
return ""
5252

5353
if user_id == bot.id:
54-
message.reply_text("Di sicuro non mi bannero' da solo.. sei pazzo?")
54+
message.reply_text("Di sicuro non mi bannero' da solo.")
5555
return ""
5656

5757
log = (
@@ -70,14 +70,14 @@ def ban(bot: Bot, update: Update, args: List[str]) -> str:
7070

7171
try:
7272
chat.kick_member(user_id)
73-
bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker
74-
message.reply_text("BANNATO!")
73+
# bot.send_sticker(chat.id, BAN_STICKER) # banhammer sticker
74+
message.reply_text("Utente rimosso.")
7575
return log
7676

7777
except BadRequest as excp:
7878
if excp.message == "Reply message not found":
7979
# Do not reply
80-
message.reply_text("BANNATO!", quote=False)
80+
message.reply_text("Utente rimosso.", quote=False)
8181
return log
8282
else:
8383
LOGGER.warning(update)
@@ -88,7 +88,7 @@ def ban(bot: Bot, update: Update, args: List[str]) -> str:
8888
chat.id,
8989
excp.message,
9090
)
91-
message.reply_text("Diamine, non riesco a bannare questo utente.")
91+
message.reply_text("Impossibile rimuovere questo membro.")
9292

9393
return ""
9494

@@ -119,11 +119,11 @@ def temp_ban(bot: Bot, update: Update, args: List[str]) -> str:
119119
raise
120120

121121
if is_user_ban_protected(chat, user_id, member):
122-
message.reply_text("A volte mi piacerebbe tanto poter bannare gli admin...")
122+
message.reply_text("Impossibile rimuovere gli altri admin.")
123123
return ""
124124

125125
if user_id == bot.id:
126-
message.reply_text("Di sicuro non mi bannero' da solo.. sei pazzo?")
126+
message.reply_text("Di sicuro non mi bannero' da solo.")
127127
return ""
128128

129129
if not reason:
@@ -164,14 +164,14 @@ def temp_ban(bot: Bot, update: Update, args: List[str]) -> str:
164164
try:
165165
chat.kick_member(user_id, until_date=bantime)
166166
bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker
167-
message.reply_text("BANNATO! L'utente verra' bannato per {}.".format(time_val))
167+
message.reply_text("L'utente verra' bannato per {}.".format(time_val))
168168
return log
169169

170170
except BadRequest as excp:
171171
if excp.message == "Reply message not found":
172172
# Do not reply
173173
message.reply_text(
174-
"BANNATO! L'utente verra' bannato per {}.".format(time_val), quote=False
174+
"L'utente verra' bannato per {}.".format(time_val), quote=False
175175
)
176176
return log
177177
else:
@@ -183,7 +183,7 @@ def temp_ban(bot: Bot, update: Update, args: List[str]) -> str:
183183
chat.id,
184184
excp.message,
185185
)
186-
message.reply_text("Diamine, non riesco a bannare questo utente.")
186+
message.reply_text("Impossibile bannare questo utente.")
187187

188188
return ""
189189

@@ -214,7 +214,7 @@ def kick(bot: Bot, update: Update, args: List[str]) -> str:
214214

215215
if is_user_ban_protected(chat, user_id):
216216
message.reply_text(
217-
"Non hai idea di quanto mi piacerebbe poter kickare gli admins..."
217+
"Impossibile rimuovere gli admin."
218218
)
219219
return ""
220220

@@ -299,7 +299,7 @@ def unban(bot: Bot, update: Update, args: List[str]) -> str:
299299
return ""
300300

301301
chat.unban_member(user_id)
302-
message.reply_text("Yep, questo utente può tornare tra noi!")
302+
message.reply_text("Questo utente può tornare tra noi!")
303303

304304
log = (
305305
"<b>{}:</b>"

tg_bot/modules/blacklist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def blacklist(bot: Bot, update: Update, args: List[str]):
3737
split_text = split_message(filter_list)
3838
for text in split_text:
3939
if text == BASE_BLACKLIST_STRING:
40-
msg.reply_text("Non sono presenti triggger nella blacklist!")
40+
msg.reply_text("Non sono presenti trigger nella blacklist!")
4141
return
4242
msg.reply_text(text, parse_mode=ParseMode.HTML)
4343

@@ -114,7 +114,7 @@ def unblacklist(bot: Bot, update: Update):
114114

115115
elif not successful:
116116
msg.reply_text(
117-
"NNessuno di questi trigger esiste, quindi non sono stati rimossi.".format(
117+
"Nessuno di questi trigger esiste, quindi non sono stati rimossi.".format(
118118
successful, len(to_unblacklist) - successful
119119
),
120120
parse_mode=ParseMode.HTML,

tg_bot/modules/cust_filters.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def reply_filter(bot: Bot, update: Update):
215215
message.reply_text(
216216
"Sembra che tu stia provando a usare un protocollo url non supportato. "
217217
"Telegram non supporta i bottoni con alcuni procolli come per esempio: tg://."
218-
"Per favore riprova oppure chiedi aiuto qui: @MarieSupport."
218+
"Per favore riprova oppure chiedi aiuto qui: https://t.me/python_ita."
219219
)
220220
elif excp.message == "Reply message not found":
221221
bot.send_message(
@@ -228,7 +228,7 @@ def reply_filter(bot: Bot, update: Update):
228228
else:
229229
message.reply_text(
230230
"Questa nota non può essere inviata, è formattata in modo scorretto. "
231-
"Chiedi su @MarieSupport se non riesci a capire perché."
231+
"Chiedi su https://t.me/python_ita se non riesci a capire perché."
232232
)
233233
LOGGER.warning(
234234
"Message %s could not be parsed", str(filt.reply)

0 commit comments

Comments
 (0)