示例#1
0
    def handle_socket(self, server):
        if server:
            sock = self.server_sock
            remote_sock = self.client_sock
            cipher = self.decrypt_cipher
        else:
            sock = self.client_sock
            remote_sock = self.server_sock
            cipher = None

        fd = sock.makefile('rb')
        while True:
            data = self.read_message(fd, cipher)
            if not data:
                break

            try:
                if handler.want_reload():
                    reload(handler)
                handler.handle_message(self, server, data)
            except:
                traceback.print_exc()

        remote_sock.shutdown(socket.SHUT_RDWR)
        remote_sock.close()
示例#2
0
文件: proxy.py 项目: recast/teraproxy
    def handle_socket(self, server):
        if server:
            sock = self.server_sock
            remote_sock = self.client_sock
            cipher = self.decrypt_cipher
        else:
            sock = self.client_sock
            remote_sock = self.server_sock
            cipher = None

        fd = sock.makefile('rb')
        while True:
            data = self.read_message(fd, cipher)
            if not data:
                break

            try:
                if handler.want_reload():
                    reload(handler)
                handler.handle_message(self, server, data)
            except:
                traceback.print_exc()

        remote_sock.shutdown(socket.SHUT_RDWR)
        remote_sock.close()
import requests
from handler import handle_message
lil = 0
while True:
    res = requests.get(
        "https://api.telegram.org/bot468389348:AAFk47PMcPIsE_2B5eukGpFUC2CWCGWzdKc/getUpdates",
        params={"offset": lil})
    d = res.json()
    print(d)

    for elem in d["result"]:
        lil = elem["update_id"] + 1
        try:
            text = elem["message"]["text"]
            ans = handle_message(text)
            chat_id = elem["message"]["chat"]["id"]
            requests.post(
                "https://api.telegram.org/bot468389348:AAFk47PMcPIsE_2B5eukGpFUC2CWCGWzdKc/sendMessage",
                params={
                    "chat_id": chat_id,
                    "text": ans
                })
        except Exception as e:
            print(e)
示例#4
0
import requests 
from handler import handle_message 
token = "https://api.telegram.org/bot540889680:AAHVdAwR1JxSfJWP61-i0g1eVK-LoK9QfOU/"
last_update = 0
while True:
	temp = dict()
	temp["offset"] = last_update
	req = requests.get(token + "getUpdates", params=temp)
	Inp = req.json()
	print(Inp)

	for el in Inp["result"]:	
		if "message" not in el:
			continue
		else:
			if "text" not in el["message"]:
				continue
		last_update = max(el["update_id"], last_update)
		last_update += 1
		text = el["message"]["text"]
		nick = str(el["message"]["from"]["id"]) + "\n"
		chat_id = el["message"]["from"]["id"]
		ans = handle_message(text, nick)
		requests.post(token + "sendMessage", params={"chat_id": chat_id, "text": "\n".join(ans)})
示例#5
0
import requests
from handler import handle_message


max_update_id = -1
chat_ids_of_users = set()
while True:
    res = requests.get("https://api.telegram.org/bot482414971:AAFJ4-3T9oXmPahj1QPJTRbq2uHH-i7wwtc/getUpdates", params={"offset": -1})
    d = res.json()
    if d["result"] and d["result"][0]["update_id"] > max_update_id:
        max_update_id = max(max_update_id, d["result"][0]["update_id"])
        for elem in d["result"]:
            text = elem["message"]["text"]
            ans = handle_message(text, elem["message"]["chat"]["id"])
            chat_id = elem["message"]["chat"]["id"]
            if text == "/start":
                chat_ids_of_users.add(chat_id)
                continue
            if ans and text != "/show":
                for chat in chat_ids_of_users:
                    requests.post("https://api.telegram.org/bot482414971:AAFJ4-3T9oXmPahj1QPJTRbq2uHH-i7wwtc/sendMessage",
                                  params={"chat_id": chat, "text": ans})
            elif ans and text == "/show":
                requests.post("https://api.telegram.org/bot482414971:AAFJ4-3T9oXmPahj1QPJTRbq2uHH-i7wwtc/sendMessage",
                              params={"chat_id": chat_id, "text": ans})