def fromvktotl(list_of_alles, list_of_imnts): global url global users if not list_of_alles: return toall = [] toimnt = [] while list_of_alles: toall.append(' : '.join(list_of_alles.pop(0)[1:])) toall = ';\n'.join(toall) # making message what to send to users with mode 'imnt' while list_of_imnts: toimnt.append(' : '.join(list_of_imnts.pop(0)[1:])) toimnt = ';\n'.join(toimnt) # cycling through user`s table for x in users.keys(): # loading user`s mode and ID usermode, userid = users[x][1], x # doesn`t send if user`s mode is 'no' if usermode == 'no': continue # sends important messages to user with 'imnt' mode elif toimnt and usermode == 'imnt': tl.sendmsg(url, userid, toimnt) # sends all messages to user with 'all' mode elif usermode == 'all': tl.sendmsg(url, userid, toall)
def send_help(message): global url # loading help message f = open('files/info.db', 'r') helpmsg = f.read().split('VK@@##@@TL')[1].strip() f.close() # sending description tl.sendmsg(url, message[1], helpmsg)
def send_stat(message, curr_stat): global odmins global url if message[1] not in odmins: return out_string = '''Temp: {0} C; \nSpeed_TL: {1}; \nSpeed_VK: {2}; \nPID_VK: {3}; \nPID_TL: {4}''' tl.sendmsg(url, message[1], out_string.format(curr_stat['temp'], curr_stat['iter_tl'], curr_stat['iter_vk'], curr_stat['PID_VK'], curr_stat['PID_TL']))
def send_citation(message): global url if get_tl_user(message[1]): # loading and choosing citation f = open('files/citations.db', 'r') tosend = randchoice(f.read().split('\n\n')) f.close() # sending citation tl.sendmsg(url, message[1], tosend)
def send_bug(message): global url global odmins curruser = get_tl_user(message[1]) if not curruser: return for x in odmins: tl.sendmsg(url, x, 'BUG! {0}'.format(message[2][5:]))
def send_tl_users(message): global odmins global url if message[1] not in odmins: return user_text = [] for x in users.keys(): user_text.append(' : '.join([x, users[x][0], users[x][1]])) tl.sendmsg(url, message[1], '\n'.join(user_text))
def change_users_mode(message): global url curruser = get_tl_user(message[1]) if not curruser or not message[2][6:] in ['all', 'no', 'imnt']: return users[message[1]] = users[message[1]][0], message[2][6:] tl.sendmsg(url, message[1], "The mode has been changed") write_users_table()
def change_users_name(message): global url global users # getting new nickname and writing it to log curruser = get_tl_user(message[1]) if not curruser: return users[message[1]] = message[2][8:], users[message[1]][1] tl.sendmsg(url, message[1], "The nickname has been changed") write_users_table()
def send_adm_msg(message, tl_msgs): global odmins global url if message[1] not in odmins: return curruser = message[1] tl_msgs.append('{0} \n'.format(message[2][5:])) # sending info message tl.sendmsg(url, curruser, "The Admin-message will be sent soon.") for qw in users.keys(): if not qw == curruser: tl.sendmsg(url, qw, message[2][5:])
def ach_send_to_vk(message, tl_msgs): global url curruser = get_tl_user(message[1]) if not curruser: return tl_msgs.append('{0}: {1} ;\n'.format(curruser[0], message[2][5:].upper())) # sending info message tl.sendmsg(url, message[1], "The achtung will be sent soon.") for qw in users: if not qw == message[1] and not users[qw][1] == 'no': tl.sendmsg(url, qw, 'ACHTUNG! From TL`s {0}: {1};'.format(curruser[0], message[2][5:].upper()))
def msg_send_to_vk(message, tl_msgs): global url curruser = get_tl_user(message[1]) if not curruser: return tl_msgs.append('{0}: {1} ;\n'.format(curruser[0], message[2][5:])) # sending info message tl.sendmsg(url, message[1], "The message will be sent soon.") for qw in users.keys(): if not qw == message[1] and users[qw][1] == 'all': tl.sendmsg(url, qw, 'From TL`s {0}: {1};'.format(curruser[0], message[2][5:]))
def send_vk_log(message, msghistory): global users global url if get_tl_user(message[1]): # loading list of VK messages vk_messages = msghistory.read().strip(' ;').strip("@ ").replace(' :: ', ' : ').split(';\n@') # making more readable list of messages and deleting users IDs newmsg = [] for y in vk_messages: newmsg.append(' : '.join(y.split(' : ')[1:]).strip(' ;')) # checking if TL user typed all correct. please do not beat me for this try: tosend = '\n'.join(newmsg[-int(message[2][5:].strip()):]) except ValueError: tosend = 'You typed incorrect value. Maybe you requested more messages ' \ 'I have, or you typed non integer number.' # sending message with ErrorMessage or log tl.sendmsg(url, message[1].strip(), tosend)
def send_tl_log(message): global odmins global url if message[1] not in odmins: return # loading TL messages list f = open("files/tl_msgs.db", "r") messages = f.read().strip(' ;').strip("@ ").replace(' :: ', ' : ').split(';\n@') f.close() newmsg = [] # making them more readable and deleting their [messages`] IDs for y in messages: newmsg.append(' : '.join(y.split(' : ')[1:]).strip(' ;')) # checking if Odmin typed correct value try: tosend = '\n'.join(newmsg[-int(message[2][7:]):]) except ValueError: tosend = 'You typed incorrect value. Maybe you requested more messages I have, or you typed non integer number.' # sending messages tl.sendmsg(url, message[1], tosend)
def auth_user(message): global url global users # allows users to log in via 64 byte token (really it length is 32 byte, # but it has 64 symbols in hexademical mode); # Also checks if length of typed token is true; if 60 < len(message[2]) < 75: # loading list of tokens f = open('files/tokens.db', 'r') tokens = f.read().split('\n') f.close() if not tokens: return # getting hash (other name is publickey) of the token (secretkey) publickey = gethash(message[2][6:71].strip()) # checking if hash(publickey) is in token`s list and if this user is not logged in if publickey in tokens and not get_tl_user(message[1]): # writing new user to user table users[message[1]] = tl.get_users_name(url, message), 'all' # sending welcome message with some info about user write_users_table() tl.sendmsg(url, message[1], "Welcome! You are now successfully authenticated as {0}." "\nYou can change your nicname via /chname <new_nick> or you can " "view a help message via /help.".format(users[message[1]][0])) # writing list of publickeys without recently used publickey tokens.pop(tokens.index(publickey)) g = open('files/tokens.db', 'w') g.write('\n'.join(tokens)) g.close() # if computed hash not in the list of available publickeys increase number of tryes of current user elif publickey not in tokens and not get_tl_user(message[1])[0]: # sending warning message tl.sendmsg(url, message[1], 'Wrong key.') # sending message if user already logged in or typed absolutely wrong token or user is in Black_List else: tl.sendmsg(url, message[1], 'You are already logged in. You can change your nick via /chname <new_nick>')
def send_users_info(message): curruser = get_tl_user(message[1]) if not curruser: return tl.sendmsg(url, message[1], "You are logged in as {0} with recieving {1} messages.".format(curruser[0], curruser[1]))