-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (47 loc) · 1.65 KB
/
main.py
File metadata and controls
62 lines (47 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import botogram
import random
from config import *
# Prepara il bot
bot = botogram.create(TELEGRAM_TOKEN)
# Lista dei messaggi
messages = (
"Compra un raspberry pi!",
"Ti sei ricordato di comparare un raspberry pi?",
"Compralo!",
"Anche Pelloni ne dovrebbe compare uno!",
"Costa solo 45€!",
"Se vuoi c'è anche quello da 5€!"
)
# Il messaggio in chat contiene 'raspberry'
@bot.message_contains("raspberry")
def raspberry_message(chat, message):
"""Invia un messaggio a random dalla lista messages"""
send_raspberry_message(chat, message)
# Comando /raspberry
@bot.command("raspberry")
def raspberry_commad(chat, message):
"""Invia un messaggio a random dalla lista messages"""
send_raspberry_message(chat, message)
# Comando /raspberrypi
@bot.command("raspberrypi")
def raspberrypi_commad(chat, message):
"""Invia un messaggio a random dalla lista messages"""
send_raspberry_message(chat, message)
def send_raspberry_message(chat, message):
"""Funziona per inviare un messaggio a random dalla lista messages"""
msg_n = random.randint(0, len(messages) - 1)
msg = messages[msg_n]
chat.send(msg)
log_request(chat, message)
# Logga in console che qualcuno ha fatto una richiesta
def log_request(chat, message):
# Un utente potrebbe non avere un nome utente
if message.from_.username is None:
# Se non hanno un username logghiamo il nome
print("Ricevuto messaggio da chatid: " + message.from_.name)
else:
# Se hanno un username logghiamo l'username
print("Ricevuto messaggio da: " + message.from_.username)
if __name__ == '__main__':
# Avvia il bot
bot.run()