-
Notifications
You must be signed in to change notification settings - Fork 1
/
bott.py
executable file
·46 lines (36 loc) · 1.21 KB
/
bott.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
import telepot
import config
import os
def on_chat_message(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
user_id = msg['from']['id']
if user_id != config.user_id:
bot.sendMessage(chat_id, "NOT AUTHORIZED!!!")
return
first_name = msg["from"]["first_name"]
last_name = msg["from"]["last_name"]
name = first_name.lstrip() + ' ' + last_name.lstrip()
if content_type == 'text':
txt = msg['text']
if txt == '/list':
bot.sendMessage(chat_id, '/list - list of all commands \n/command1 - Description')
elif txt == '/command1':
os.system(config.commandsPath+"command1.sh")
bot.sendMessage(chat_id, 'command1 executed!')
else:
bot.sendMessage(chat_id, "Hi %s type /list for the list of all commands."%name)
if content_type == 'audio':
autor = msg['audio']['performer']
title = msg['audio']['title']
file_id = msg['audio']['file_id']
file_name = autor.lstrip() +' - '+ title.lstrip() + '.mp3'
if file_name != None:
bot.download_file(file_id,config.savePath+file_name)
bot.sendMessage(chat_id, 'Hi %s, %s saved!'%(name,file_name))
return
bot = telepot.Bot(config.token)
bot.message_loop(on_chat_message)
print 'Listening ...'
import time
while 1:
time.sleep(10)