-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
126 lines (98 loc) · 4.42 KB
/
bot.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
116
117
118
119
120
121
122
123
124
125
126
from time import sleep
import telepotpro
from telepotpro import Bot, glance
from telepotpro.exception import TelegramError, BotWasBlockedError
from telepotpro.namedtuple import InlineQueryResultArticle, InlineQueryResultPhoto, InputTextMessageContent
from threading import Thread
from datetime import datetime, timedelta
from json import load as jsload
from os.path import abspath, dirname, join
import phrase
with open(join(dirname(abspath(__file__)), "settings.json")) as settings_file:
js_settings = jsload(settings_file)
bot = Bot(js_settings["key"])
maintenance = js_settings["maintenance"]
if not maintenance:
print("Bot Started Successfully")
else:
print("WARNING! You started the bot is in maintenance mode, change this setting in settings.json")
def reply(msg):
global maintenance
chatId = msg['chat']['id']
name = msg['from']['first_name']
try:
text = msg['text']
except ValueError:
text = ""
command = getCommand(text).lower()
if not maintenance:
if command == "/dona":
bot.sendMessage(chatId, "Ecco qui il mio link PayPal, Grazie mille! ❤️\n"
"https://www.paypal.me/wapeetyofficial")
elif command == "/source":
bot.sendMessage(chatId, "Ecco qui il link Github, Aggiungi una stellina! 😘\n"
"https://github.com/WAPEETY/aatf_bot")
elif command == "/start":
bot.sendMessage(chatId, "Benvenuto❗️\n"
"\n"
"<i>Questo bot funziona inline</i>\n\n"
"Vai in una qualsiasi chat e scrivi @aatf_bot per usarlo", parse_mode="HTML")
elif command == "/help":
bot.sendMessage(chatId, "<i>Questo bot funziona inline</i>\n\n"
"Vai in una qualsiasi chat e scrivi @aatf_bot per usarlo", parse_mode="HTML")
else:
bot.sendMessage(chatId, "Comando non riconosciuto ☹️")
else:
bot.sendMessage(chatId, "⚠️ <b>Bot Attualmente in manutenzione.</b> ⚠️\n"
"<i>Ci scusiamo per il disagio.</i>", parse_mode="HTML")
def getCommand(content):
t=0
output = ""
for i in content:
if i != " " and t == 0:
output += i
else:
t = 1
return output
def on_inline_query(msg):
query_id, from_id, query_string = telepotpro.glance(msg, flavor='inline_query')
print ('Inline Query:', query_id, from_id, query_string)
global maintenance
if not maintenance:
for i in range(0, phrase.getLenght() ):
if(i == 0):
articles = [InlineQueryResultArticle(
id=i,
title= phrase.getName(i),
description= phrase.getDescription(i),
#thumb_url= ,
input_message_content=InputTextMessageContent(
message_text= phrase.getContent(i),
parse_mode="HTML"
)
)]
else:
articles += [InlineQueryResultArticle(
id=i,
title= phrase.getName(i),
description= phrase.getDescription(i),
#thumb_url= ,
input_message_content=InputTextMessageContent(
message_text= phrase.getContent(i),
parse_mode="HTML"
)
)]
bot.answerInlineQuery(query_id, articles)
else:
articles = [InlineQueryResultArticle(
id=0,
title= "⚠️ Bot in Manutenzione ⚠️",
description= "Ci scusiamo per il disagio",
input_message_content=InputTextMessageContent(
message_text="⚠️ <b>Bot Attualmente in manutenzione.</b> ⚠️ \n\n <i>Ci scusiamo per il disagio.</i>",
parse_mode="HTML"
)
)]
bot.message_loop({'chat': reply, 'inline_query': on_inline_query})
while True:
sleep(60)