def process_handler(self, conn, ip, port): try: print[ip, port], "~ has connected" receiver = RECEIVER() receiver.add_connection(conn) while 1: data = receiver.receive() if (data == ""): print[ip, port], "~", INFO.timeout break request = data.split('\r\n') operation = request[0].split() connection = "Close" for part in request: if "Connection:" in part: connection = part.split()[1] if (len(operation) >= 3): if (operation[2] != "HTTP/1.1" and operation[2] != "HTTP/1.0"): self.bad_request(receiver, "http", operation[2]) break print[ip, port], "~", operation[0], "command" self.messages = MESSAGES(operation[2]) if (operation[0] == "GET"): print[ip, port], "~ is requesting", operation[1] print[ip, port], "~ is using", operation[2] url = urlparse.urlparse(operation[1]) url_ip = url.netloc url_port = CONFIG.default_port tmp_port = url.port if (tmp_port != None): url_port = int(tmp_port) server = RECEIVER() server.connect(url_ip, url_port) result = self.get([ip, port], operation[1], data, server, receiver) if result == False: exit() self.close(server) elif (operation[0] == "POST"): self.post(receiver) elif (operation[0] == "HEAD"): self.head(receiver) else: print ERRORS.invalid_command self.bad_request(receiver, "method", operation[0]) if (connection.lower() != "keep-alive"): break else: self.bad_request(receiver, "unknown", "incorrect format") break except KeyboardInterrupt: print "\n", [ip, port], "~", INFO.killing_process print[ip, port], "~", INFO.closing_connection self.close(receiver) exit()
async def ship_top(message: Message, limit: int = 10): top_list = select.ship_count_all(group_id=message.chat.id, limit=limit) msg = MSG.get('ship_top') + '\n\n' emojis = [ '🥇', '🥈', '🥉', ] if not isinstance(top_list[0], list): top_list = [top_list] for topper in top_list: position = top_list.index(topper) + 1 user_id = topper[0] count = topper[1] name = shorter.name(select.name(user_id)) msg += f'{position if not emojis else emojis.pop(0)} : ' \ f'{name} ' \ f'({count} ship.)' \ f'\n\n' await message.reply(msg, parse_mode=PM, reply=False)
def process_handler(self, conn, ip, port): try: print[ip, port], "~ has connected" receiver = RECEIVER(conn) while 1: data = receiver.receive() if (data == False): print[ip, port], "~", INFO.timeout break request = data[0].split('\r\n') operation = request[0].split() connection = "Close" for part in request: if "Connection:" in part: connection = part.split()[1] if (len(operation) >= 3): if (operation[2] != "HTTP/1.1" and operation[2] != "HTTP/1.0"): self.bad_request(receiver, "http", operation[2]) break print[ip, port], "~", operation[0], "command" self.messages = MESSAGES(operation[2]) if (operation[0] == "GET"): print[ip, port], "~ is requesting", operation[1] print[ip, port], "~ is using", operation[2] self.get(operation[1], receiver) elif (operation[0] == "POST"): print[ip, port], "~ is requesting", operation[1] print[ip, port], "~ is using", operation[2] new_val = request[len(request) - 1].split('=')[1] self.post(operation[1], receiver, new_val) elif (operation[0] == "PUT"): self.put(receiver) elif (operation[0] == "DELETE"): self.delete(receiver) else: print ERRORS.invalid_command self.bad_request(receiver, "method", operation[0]) if (operation[2] == "HTTP/1.0" or connection.lower() != "keep-alive"): break else: self.bad_request(receiver, "unknown", "incorrect format") break except KeyboardInterrupt: print "\n", [ip, port], "~", INFO.killing_process print[ip, port], "~", INFO.closing_connection self.close(receiver) exit()
async def top_gays(message: Message, limit: int = 10): top_list = select.members_and_balance(group_id=message.chat.id, limit=limit) msg = MSG.get('gay_top') + '\n\n' emojis = ['🏳️🌈', '🍑', '🔥', '🍩', '🌝', '🇩🇪', '🦄'] if not isinstance(top_list[0], list): top_list = [top_list] for topper in top_list: position = top_list.index(topper) + 1 name = select.name(topper[0]) balance = topper[1] name = shorter.name(name) msg += f'{position} ' \ f'{"" if not emojis else emojis.pop(0)} ' \ f'{name}: {balance} GC ' \ f'\n\n' # f'[{name}](tg://user?id={username}): {balance} GC ' \ await message.reply(msg, parse_mode=PM)
async def ship(message: types.Message): add_or_update_user(message, karma_bonus=0.1) mems = select.members_and_karma(message.chat.id) if not isinstance(mems[0], list): await message.reply(MSG.get('not_enough_users')) return tickets = [] print(mems) for mem in mems: for karma in range(int(mem[2])): tickets.append(mem[0]) first = choice(tickets) second = choice(tickets) while first == second: second = choice(tickets) remove.shippers(message.chat.id) insert.shippers(message.chat.id, first, second, time()) await message.reply( f"♥♥♥♥ {MSG.get('ship_success')} ♥♥♥♥\n" f"[{shorter.name(select.name(first))}](tg://user?id={first})" f" {MSG.get('and')} " f"[{shorter.name(select.name(second))}](tg://user?id={second})\n" f"\n" f"{MSG.get('nice_day')}\n\n" f"{MSG.get('next_ship')}", parse_mode=PM) ship_c_1 = select.ship_count(message.chat.id, first) ship_c_2 = select.ship_count(message.chat.id, second) print(ship_c_1, ship_c_2) if len(ship_c_1) == 0: ship_c_1 = [0] insert.ship_count( group_id=message.chat.id, user_id=first, ) if len(ship_c_2) == 0: ship_c_2 = [0] insert.ship_count( group_id=message.chat.id, user_id=second, ) ship_c_1 = int(ship_c_1[0]) ship_c_2 = int(ship_c_2[0]) update.ship_count(group_id=message.chat.id, user_id=first, value=ship_c_1 + 1) update.ship_count(group_id=message.chat.id, user_id=second, value=ship_c_2 + 1)
def __init__(self): self.messages = MESSAGES("HTTP/1.0") return
async def echo(message: types.Message): if message.text.lower() in MESSAGES.keys(): text = MESSAGES[message.text] else: text = MESSAGES['unknown'] await message.reply(text, reply=False)