forked from UNICT-DMI/Telegram-DMI-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·115 lines (93 loc) · 5.58 KB
/
main.py
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# -*- coding: utf-8 -*-
from functions import *
with open('config/settings.yaml') as yaml_config:
config_map = yaml.load(yaml_config, Loader=yaml.SafeLoader)
bot = telegram.Bot(config_map["token"])
def logging_message(update: Update, context: CallbackContext):
try:
message_id = update.message.message_id #ID MESSAGGIO
user = update.message.from_user # Restituisce un oggetto Telegram.User
chat = update.message.chat # Restituisce un oggetto Telegram.Chat
text = update.message.text #Restituisce il testo del messaggio
date = update.message.date #Restituisce la data dell'invio del messaggio
message = "\n___ID MESSAGE: " + str(message_id) + "____\n" + \
"___INFO USER___\n" + \
"user_id:" + str(user.id) + "\n" + \
"user_name:" + str(user.username) + "\n" + \
"user_firstlastname:" + str(user.first_name) + " " + str(user.last_name) + "\n" + \
"___INFO CHAT___\n" + \
"chat_id:" + str(chat.id) + "\n" + \
"chat_type:" + str(chat.type)+"\n" + "chat_title:" + str(chat.title) + "\n" + \
"___TESTO___\n" + \
"text:" + str(text) + \
"date:" + str(date) + \
"\n_____________\n"
log_tmp = open("logs/logs.txt","a+")
log_tmp.write("\n"+message)
except:
pass
def main():
updater = Updater(TOKEN, request_kwargs={'read_timeout': 20, 'connect_timeout': 20}, use_context=True)
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.all, logging_message),1)
dp.add_handler(CallbackQueryHandler(button_handler))
#Easter Egg
dp.add_handler(CommandHandler('smonta_portoni',smonta_portoni))
dp.add_handler(CommandHandler('santino',santino))
dp.add_handler(CommandHandler('prof_sticker' ,prof_sticker))
dp.add_handler(MessageHandler(Filters.regex('/lezioni cazzeggio'), bladrim))
dp.add_handler(CommandHandler('leiCheNePensaSignorina',lei_che_ne_pensa_signorina))
# dp.add_handler(MessageHandler(Filters.regex('/forum'), forum_bot))
#Informative command
dp.add_handler(CommandHandler('sdidattica', lambda update, context: informative_callback(update, context, 'sdidattica')))
dp.add_handler(CommandHandler('sstudenti', lambda update, context: informative_callback(update, context, 'sstudenti')))
dp.add_handler(CommandHandler('cea', lambda update, context: informative_callback(update, context, 'cea')))
dp.add_handler(CommandHandler('ersu', lambda update, context: informative_callback(update, context, 'ersu')))
dp.add_handler(CommandHandler('ufficioersu', lambda update, context: informative_callback(update, context, 'ufficioersu')))
dp.add_handler(CommandHandler('urp', lambda update, context: informative_callback(update, context, 'urp')))
dp.add_handler(CommandHandler('biblioteca', lambda update, context: informative_callback(update, context, 'biblioteca')))
dp.add_handler(CommandHandler('cus', lambda update, context: informative_callback(update, context, 'cus')))
dp.add_handler(CommandHandler('lezioni', lambda update, context: lezioni(update, context)))
dp.add_handler(CommandHandler('esami', lambda update, context: esami(update, context)))
dp.add_handler(CommandHandler('prof', prof))
dp.add_handler(CommandHandler('aulario', lambda update, context: informative_callback(update, context, 'aulario')))
dp.add_handler(CommandHandler('help',help))
dp.add_handler(CommandHandler('contributors', lambda update, context: informative_callback(update, context, 'contributors')))
dp.add_handler(CommandHandler('rappresentanti', lambda update, context: informative_callback(update, context, 'rappresentanti')))
dp.add_handler(CommandHandler('rappresentanti_dmi', lambda update, context: informative_callback(update, context, 'rappresentanti_dmi')))
dp.add_handler(CommandHandler('rappresentanti_informatica', lambda update, context: informative_callback(update, context, 'rappresentanti_informatica')))
dp.add_handler(CommandHandler('rappresentanti_matematica', lambda update, context: informative_callback(update, context, 'rappresentanti_matematica')))
dp.add_handler(CommandHandler('report', report))
dp.add_handler(CommandHandler('chatid',give_chat_id))
dp.add_handler(CommandHandler('send_log', send_log))
dp.add_handler(CommandHandler('send_chat_ids', send_chat_ids))
dp.add_handler(CommandHandler('errors', send_errors))
dp.add_handler(CommandHandler('start', start))
dp.add_handler(CommandHandler('avviso', newscommand))
dp.add_handler(CommandHandler('cloud', lambda update, context: informative_callback(update, context, 'cloud')))
#JobQueue
j = updater.job_queue
#j.run_repeating(avviso, interval=60) # job_dmi_news
j.run_repeating(updater_lep, interval=86400, first=0) # job_updater_lep (24h)
if (config_map['debug']['disable_drive'] == 0):
dp.add_handler(CommandHandler('drive',drive))
if config_map['debug']['disable_gitlab'] == 0:
dp.add_handler(CommandHandler('git', git))
dp.add_handler(CommandHandler('gitlab', git))
if config_map['debug']['disable_drive'] == 0 or \
config_map['debug']['disable_gitlab'] == 0:
dp.add_handler(MessageHandler(Filters.regex('/request'), request))
dp.add_handler(MessageHandler(Filters.regex('/add_db'), add_db))
if (config_map['debug']['disable_db'] == 0):
dp.add_handler(CommandHandler('stats',stats))
dp.add_handler(CommandHandler('stats_tot',stats_tot))
if (config_map['debug']['disable_chatid_logs'] == 0):
dp.add_handler(MessageHandler(Filters.regex('/news'), news_))
dp.add_handler(CommandHandler('spamnews',spamnews))
dp.add_handler(CommandHandler('disablenews',disablenews))
dp.add_handler(CommandHandler('enablenews',enablenews))
dp.add_handler(CallbackQueryHandler(callback))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()