-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTelegramBox.py
98 lines (66 loc) · 2.05 KB
/
TelegramBox.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
# encoding: utf8
import urllib
import urllib2
import time
import json
import sys
from poster.encode import multipart_encode
from poster.streaminghttp import register_openers
import subprocess
from TelegramBot import (Bot)
API = 'https://api.telegram.org/bot'
TOKEN = '95471063:AAHADeZJXG1yizCj0B16ZDJxQLDFf-2Slgs'
PAVEL = 94766527
URL = API + TOKEN
# noinspection PyPep8Naming
def getUpdates():
get = URL + '/getUpdates'
response = urllib2.urlopen(get)
return response.read()
INVALID_UPDATE_ID = 0
global last_update_id
last_update_id = INVALID_UPDATE_ID
def getCommand():
js = json.loads(getUpdates())
update_obj = js['result'][-1]
global last_update_id
if last_update_id == INVALID_UPDATE_ID:
last_update_id = update_obj['update_id']
return None
if update_obj['update_id'] != last_update_id:
last_update_id = update_obj['update_id']
return update_obj['message']['text']
return None
def sendMessage(chat_id, text):
sendMessage = {
'chat_id': chat_id,
'text': text
}
get = URL + '/sendMessage?' + urllib.urlencode(sendMessage)
response = urllib2.urlopen(get)
def sendPhoto(chat_id, image_file):
register_openers()
values = {
'chat_id': chat_id,
'photo': open(image_file, 'rb')
}
data, headers = multipart_encode(values)
request = urllib2.Request(URL + '/sendPhoto?', data, headers)
response = urllib2.urlopen(request)
# bot = Bot(TOKEN)
# bot.sendMessage(PAVEL, 'Тест бота')
# sys.exit(0)
while True:
command = getCommand()
if None != command:
if 'screenshot' == command:
sendMessage(PAVEL, 'Щас сделаю, погодь')
time.sleep(1)
subprocess.Popen(['import', '-window', 'root', 'screenshot.png'])
time.sleep(3)
sendPhoto(PAVEL, 'screenshot.png')
time.sleep(1)
sendMessage(PAVEL, 'Поймал???')
if 'damn' == command:
sendMessage(PAVEL, "Нахуй пошёл!!!")
time.sleep(1)