-
Notifications
You must be signed in to change notification settings - Fork 0
/
botaction.py
40 lines (33 loc) · 892 Bytes
/
botaction.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
from bot import telegram_chatbot
update_id=None
bot = telegram_chatbot()
def make_reply(message):
if message is not None:
message=message.lower()
reply = "The message has:\n"
all_freq = {}
for i in message:
if i in all_freq:
all_freq[i] += 1
else:
all_freq[i] = 1
for i in sorted(all_freq):
reply+=str(all_freq[i])+" - "+i+"\n"
return reply
while True:
print("...")
updates = bot.get_updates(offset=update_id)
updates = updates["result"]
if updates:
for item in updates:
update_id=item["update_id"]
try:
message = item["message"]["text"]
print("message="+message)
except:
message = None
if message != "/start":
senderid = item["message"]["from"]["id"]
print("senderid="+str(senderid))
reply = make_reply(message)
bot.send_message(reply,senderid)