-
Notifications
You must be signed in to change notification settings - Fork 2
/
TelBot.py
executable file
·41 lines (32 loc) · 1.17 KB
/
TelBot.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
#!/usr/bin/env python
import telepot
from telepot.loop import MessageLoop
import json
from os.path import expanduser
from os import getenv
import time
class TelBot(telepot.Bot):
def __init__(self,token):
proxyconf=getenv("http_proxy")
proxyconf=open(expanduser('~/proxy'),'r').read().strip('\n')
if proxyconf != None:
proxy_user=proxyconf.split(":")[1].strip("//")
proxy_pass=proxyconf.split(":")[2].split("@")[0]
proxy_url="http://"+proxyconf.split("@")[1]
telepot.api.set_proxy(proxy_url,(proxy_user,proxy_pass))
telepot.Bot.__init__(self,token)
# self.bot=telepot.Bot(token)
# MessageLoop(self.bot,self.handle1)
def posttry(self,msg,id):
""" Enviar mensajes al grupo por el id """
try:
# self.sendMessage(id-1001334786762,msg,parse_mode="Markdown")
print("Sent: "+msg)
except:
print('Demasiados request. Esperando 5...')
time.sleep(5)
self.posttry(msg)
def handle1(msg):
contenttype,chattype,chatid=telepot.glance(msg)
print(contenttype,chattype,chatid)
print(msg['text'])