-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.py
42 lines (39 loc) · 1.48 KB
/
server.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
from bot import telegram_chatbot
import sharebot
bot = telegram_chatbot("config.cfg")
def make_reply(msg,f_name):
reply = None
if msg == "":
reply = "Hello {}, Welcome to My Telegram Bot. Enter -- /help -- for help".format(f_name)
elif msg == "/help":
reply = "Commands Available. \n 1. /end --> End the connection \n 2. /help --> Help details."
#reply = "hello {}".format(f_name)
else:
reply=sharebot.marketvalue(msg)
return reply
update_id = None
pName = {""}
while True:
updates = bot.get_updates(offset=update_id)
updates = updates["result"]
if updates:
for item in updates:
update_id = item["update_id"]
try:
message = str(item["message"]["text"])
f_name=str(item["message"]["from"]["first_name"])
except:
message = None
f_name=None
from_ = item["message"]["from"]["id"]
if(message == '/end' and f_name in pName):
bot.send_message("See You Again! \n Ending Connection...",from_)
pName.remove(f_name)
else:
if(pName == "" or f_name not in pName):
reply = make_reply("",f_name)
bot.send_message(reply,from_)
pName.add(f_name)
else:
reply = make_reply(message,f_name)
bot.send_message(reply,from_)