forked from soroush-app/bot-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSoroushBot.py
105 lines (81 loc) · 4.06 KB
/
SoroushBot.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
93
94
95
96
97
98
99
100
101
102
103
104
105
from client import Client
import os
from os.path import getsize
import ntpath
from moviepy.editor import VideoFileClip
class SoroushBot:
def __init__(self, bot_token):
global b
b= Client(bot_token)
def sendText(self,target_id,caption,isSendToChannel=False):
resualt=b.send_text(target_id,caption,isSendToChannel)
#resualt=[error,success]
return resualt
def imageVideoResalotion(self,path):
clip=VideoFileClip(path)
width = int(round(clip.w))
height = int(round(clip.h))
return [width,height]
def sendImage(self,target_id,image_path,image_thumbnail_path,caption,isSendToChannel=False):
rImage=b.upload_file(image_path)
#rImage=[image_error, image_url]
if rImage[1]:
rThumb = b.upload_file(image_thumbnail_path)
#rThumb=[thumbnail_error, thumbnail_url]
scale=self.imageVideoResalotion(image_path)
resualt = b.send_image(target_id, rImage[1],
ntpath.basename(image_path),
getsize(image_path), scale[0], scale[1],
rThumb[1],
caption,isSendToChannel)
#if(resualt[1] != 'OK'):
# print("paramets that gotten this function",image_path,image_thumbnail_path,caption)
return resualt
else :
#if(rImage[1] != 'OK'):
# print("paramets entered for this function",image_path,image_thumbnail_path,caption)
return rImage
def sendVideo(self,target_id,video_path,video_thumbnail_path,caption,durationSeconds=None,isSendToChannel=False):
rVideo=b.upload_file(video_path)
#rVideo=[video_error, video_url]
if rVideo[1]:
rThumb= b.upload_file(video_thumbnail_path)
#rThumb=[thumbnail_error, thumbnail_url]
if (durationSeconds==None):
clip=VideoFileClip(video_path)
durationSeconds=int(round(clip.duration))
scale=self.imageVideoResalotion(video_path)#[width,height]
resualt= b.send_video(target_id, rVideo[1],
ntpath.basename(video_path),
getsize(video_path),
durationSeconds*1000, scale[0], scale[1],
rThumb[1],
caption,isSendToChannel)
#if(resualt[1] != 'OK'):
# print("paramets that gotten this func",video_path,video_thumbnail_path,caption,durationSeconds)
return resualt
else:
#if(rVideo[1] != 'OK'):
# print("paramets entered for this func",video_path,video_thumbnail_path,caption,durationSeconds)
return rVideo
def sendFile(self,target_id,file_path,caption,isSendToChannel=False):
rFile = b.upload_file(file_path)
#rFile=[error, file_url]
resualt = b.send_attachment(target_id, rFile[1], ntpath.basename(file_path),
getsize(file_path),
caption,isSendToChannel)
return resualt
def sendLocation(self,target_id, latitude, longitude, caption='', keyboard=None,isSendToChannel=False):
resualt=b.send_location(target_id, latitude, longitude, caption, keyboard,isSendToChannel)
return resualt
def sendAudio (self, target_id, audio_path, caption, audio_duration,isSendToChannel=False):
audioUrl=b.upload_file(audio_path)
audiotype = 'PUSH_TO_TALK'
extra_params = {
'fileDuration': audio_duration*1000
}
resualt = b.send_file(target_id, caption,
ntpath.basename(audio_path), audiotype,
audioUrl[1], getsize(audio_path),
extra_params,isSendToChannel)
return resualt