-
Notifications
You must be signed in to change notification settings - Fork 5
/
maintain.py
66 lines (48 loc) · 1.49 KB
/
maintain.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
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 18 17:18:39 2017
@author: dhruv
"""
import telepot
import sys
import random
import os
from flask import Flask, request
try:
from Queue import Queue
except ImportError:
from queue import Queue
from telepot.namedtuple import *
from modules.youtube import *
from modules.wiki import *
from modules.jokes import *
from modules.feedback import *
from modules.greet import *
from modules.url import *
from modules.news import *
def text_message(msg_recieved, sender_id , msg):
print sender_id, msg_recieved
msg_list = msg_recieved.split(' ')
send_msg = "Bot is Under Maintenance ! Try After Some Time. \n Contact Botmaster At http://telegram.me/dhruvramdev"
bot.sendMessage(sender_id, send_msg)
def handle(msg):
sender_id = msg['chat']['id']
msg_recieved = msg['text']
content_type, chat_type, chat_id = telepot.glance(msg)
if content_type == 'text':
text_message(msg_recieved, sender_id , msg)
TOKEN = os.environ['TOKEN']
PORT = int(sys.argv[2])
URL = os.environ['URL'] #"https://ded974f2.ngrok.io/verify"
app = Flask(__name__)
bot = telepot.Bot(TOKEN)
update_queue = Queue() # channel between `app` and `bot`
bot.message_loop({'chat': handle}, source=update_queue)
@app.route('/verify', methods=['GET', 'POST'])
def pass_update():
update_queue.put(request.data) # pass update to bot
return 'OK'
if __name__ == '__main__':
bot.setWebhook(URL)
app.run(port=PORT , debug=True)