-
Notifications
You must be signed in to change notification settings - Fork 10
/
teleg.py
68 lines (57 loc) · 2.71 KB
/
teleg.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
#myapp/telegrambot.py
import telegram
from telegram.utils.request import Request
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, Job, JobQueue, CallbackQueryHandler
from telegram.ext import messagequeue as mq
from telegram import (ReplyKeyboardMarkup, ReplyKeyboardRemove)
from telegram import (InlineKeyboardButton, InlineKeyboardMarkup)
import logging
from cv import Id_Admins, Caption_Template
import cv
from logoadder import watermark_vid, watermark_pic
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
def handleAll(bot, update):
try:
userId = update.message.chat_id
caption = Caption_Template%(update.message.caption or ' ')#if update.message.caption!=None else ' '
# if userId in Id_Admins:
if update.message.photo:
bot.send_chat_action(userId, telegram.ChatAction.UPLOAD_PHOTO)
file_id = update.message.photo[-1]
newImage = bot.get_file(file_id)
newImage.download('files/to_watermark_pic.png')
watermark_pic()
bot.send_photo(chat_id=userId, photo=open('files/watermarked_pic.png', 'rb'), caption=caption, parse_mode=telegram.ParseMode.HTML)
elif update.message.video:
bot.send_chat_action(userId, telegram.ChatAction.UPLOAD_VIDEO)
file_id = update.message.video
newVideo = bot.get_file(file_id)
bot.send_message(update.message.chat_id, text='Watermarking')
newVideo.download('files/to_watermark_vid.mp4')
duration, width, height = watermark_vid()
bot.send_video(chat_id=userId, video=open('files/watermarked_vid.mp4', 'rb'),
duration=duration, width=width, height=height, caption=caption, parse_mode=telegram.ParseMode.HTML)
elif update.message.animation:
bot.send_chat_action(userId, telegram.ChatAction.UPLOAD_VIDEO)
file_id = update.message.animation
newVideo = bot.get_file(file_id)
bot.send_message(update.message.chat_id, text='Watermarking')
newVideo.download('files/to_watermark_vid.mp4')
watermark_vid()
bot.send_animation(chat_id=userId, animation=open('files/watermarked_vid.mp4', 'rb'), caption=caption, parse_mode=telegram.ParseMode.HTML)
except Exception as e:
bot.send_message(update.message.chat_id, text='Error :|')
logger.exception('in text message')
def error(bot, update, error):
logger.warn('Update "%s" caused error "%s"' % (update, error))
def main():
logger.info("Loading handlers for telegram bot")
updater = telegram.ext.updater.Updater(token="TOKEN", use_context=False)
dp = updater.dispatcher
dp.add_handler(MessageHandler(Filters.all, handleAll))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()