Advertisement
asl97

chatango client fix for python 3.x

Feb 2nd, 2013
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.53 KB | None | 0 0
  1. import ch
  2. import curses
  3. import threading
  4. import sys
  5. import base64
  6. import random
  7. import traceback
  8.  
  9. # Chatango client by MegaLoler
  10. # Chatango library by Lumirayz
  11. # ported to python 3.2 by ASL97
  12. # version 0.4
  13.  
  14. #changes:
  15. #default echo to false because it causes some issues
  16. #fixed online list!  although it doesn't show up until someone says something
  17. #fixed a small bug that put the cursor in the wrong place when the user list updated
  18. #added junk to the todo list lol
  19. #added fast deleted/wipe to the client(need to be mod), button "#" ~~~~asl97
  20. #added beep to the client ~~~~ asl97
  21.  
  22. #todo:
  23. #fix /part ing
  24. #make userlist appear immediately
  25. #add notation in the userlist for moderators/etc
  26. #make the lists on the left and right scrollable
  27. #moderator commands and features (like ips)
  28. #better styling (bold, underline, even blinking and stuff!)
  29. #deal with nonexistant rooms
  30. #add command history with up arrow
  31. #disconnection error handling and stuff
  32. #dynamic sizing
  33. #secret messages to individual people instead of everyone as well
  34. #custom skins
  35. #config file or somethin
  36. #cursor movement with arrow keys
  37. #nick name aliases
  38. #special page for pms
  39. #fix bugs
  40. #fix self pages not appearing with echo on
  41. #saving/loading settings
  42. #OUTPUT MACROS!  that would be epic
  43. #automated responses, and preprogrammed/saved messages, etc
  44. #away feature that tells people you are away if you are away and someone says yourname
  45. #log loading
  46. #name highlighting
  47.  
  48. activeRoom = None
  49. generalBuffer = []
  50. contents = ["", "", ""]
  51. focus = 1
  52. raw = False
  53. disguise = "*hidden*"
  54. pages = {}
  55. echo = False
  56.  
  57. screen = curses.initscr()
  58. curses.noecho()
  59. curses.start_color()
  60.  
  61. HELP_MSG = "Press TAB to switch between the three text feilds at the bottom.  Type in room names on the left to connect to rooms.  Once connected, type in messages in the middle.  Type in private messages on the right.  To toggle between open rooms press \"`\".  To toggle between private message recipients press \"~\".  The selected recipient will be highlighted in red.  Type /commands in the middle when connected to a room to get a list of commands that you can use.  Press ESC twice to exit the client."
  62.  
  63. size = screen.getmaxyx()
  64. WIDTH = int(size[1])
  65. HEIGHT = int(size[0])
  66. HALF = int(WIDTH / 2)
  67. QUARTER = int(WIDTH / 4)
  68.  
  69. RED = 1
  70. YELLOW = 2
  71. GREEN = 3
  72. CYAN = 4
  73. BLUE = 5
  74. MAGENTA = 6
  75. NORMAL = 7
  76. SECRET = 8
  77.  
  78. curses.init_pair(RED, curses.COLOR_RED, curses.COLOR_BLACK)
  79. curses.init_pair(YELLOW, curses.COLOR_YELLOW, curses.COLOR_BLACK)
  80. curses.init_pair(GREEN, curses.COLOR_GREEN, curses.COLOR_BLACK)
  81. curses.init_pair(CYAN, curses.COLOR_CYAN, curses.COLOR_BLACK)
  82. curses.init_pair(BLUE, curses.COLOR_BLUE, curses.COLOR_BLACK)
  83. curses.init_pair(MAGENTA, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
  84. curses.init_pair(NORMAL, curses.COLOR_WHITE, curses.COLOR_BLACK)
  85. curses.init_pair(SECRET, curses.COLOR_BLACK, curses.COLOR_WHITE)
  86.  
  87. def printLine(string, color=NORMAL):
  88.     generalBuffer.append((string, color))
  89.     while len(generalBuffer) > HEIGHT - 3: del generalBuffer[0]
  90.  
  91. def addMessage(string, color=NORMAL):
  92.     for string in string.split("\n"):
  93.         buf = ""
  94.         for i in string:
  95.             buf += i
  96.             if len(buf) >= HALF:
  97.                 printLine(buf, color)
  98.                 buf = ""
  99.         if buf != "": printLine(buf, color)
  100.     if activeRoom == None:
  101.         drawChat()
  102.         screen.refresh()
  103.  
  104. def hexToDec(h):
  105.     h = h.lower()
  106.     if h == "f":
  107.         return 15
  108.     elif h == "e":
  109.         return 14
  110.     elif h == "d":
  111.         return 13
  112.     elif h == "c":
  113.         return 12
  114.     elif h == "b":
  115.         return 11
  116.     elif h == "a":
  117.         return 10
  118.     else:
  119.         try:
  120.             return int(h)
  121.         except:
  122.             return 0
  123.  
  124. def hexToAnsi(col):
  125.     if col[0] == "#": col = col[1:]
  126.     if len(col) == 3:
  127.         r = hexToDec(col[0])
  128.         g = hexToDec(col[1])
  129.         b = hexToDec(col[2])
  130.     elif len(col) == 6:
  131.         r = hexToDec(col[0])
  132.         g = hexToDec(col[2])
  133.         b = hexToDec(col[4])
  134.     else:
  135.         return NORMAL
  136.  
  137.     r = r > 7
  138.     g = g > 7
  139.     b = b > 7
  140.  
  141.     if r and g and b:
  142.         return NORMAL
  143.     if r and g:
  144.         return YELLOW
  145.     if g and b:
  146.         return CYAN
  147.     if r and b:
  148.         return MAGENTA
  149.     if r:
  150.         return RED
  151.     if g:
  152.         return GREEN
  153.     if b:
  154.         return BLUE
  155.     else:
  156.         return NORMAL
  157.  
  158. def printLineR(r, string, color=NORMAL):
  159.     r.chatBuffer.append((string, color))
  160.     while len(r.chatBuffer) > HEIGHT - 3: del r.chatBuffer[0]
  161.  
  162. def addMessageR(r, string, color=NORMAL):
  163.     for string in string.split("\n"):
  164.         buf = ""
  165.         for i in string:
  166.             buf += i
  167.             if len(buf) >= HALF:
  168.                 printLineR(r, buf, color)
  169.                 buf = ""
  170.         if buf != "": printLineR(r, buf, color)
  171.     if activeRoom == r:
  172.         drawChat()
  173.         screen.refresh()
  174.     else:
  175.         r.new = True
  176.         drawRooms()
  177.         screen.refresh()
  178.  
  179. def page(user, message):
  180.     if user.lower() in pages.keys():
  181.         pages[user.lower()].append(message)
  182.     else:
  183.         pages[user.lower()] = [message]
  184.  
  185. def logMessage(message):
  186.     f = open("log", "a")
  187.     f.write(message.user.name + ": " + message.raw + "\n")
  188.     f.close()
  189.  
  190. def secretEncrypt(message, k):
  191.     message = k + message
  192.     message = base64.b64encode(message.encode('ascii'))
  193.     insert = base64.b64encode(k.encode('ascii')*len(k))[:-2]
  194.     location = random.randint(1, len(message))
  195.     first = message[:location]
  196.     if location == len(message):
  197.         last = ""
  198.     else:
  199.         last = message[location:]
  200.     message = first + insert + last
  201.     message = base64.b64encode(message + k.encode('ascii'))
  202.     return message
  203.  
  204. def secretDecrypt(message, k):
  205.     m = message
  206.     try:
  207.         message = base64.b64decode(bytes(message.split("'")[1], "ascii"))[:-len(k)]
  208.         insert = base64.b64encode(k.encode('ascii')*len(k))[:-2]
  209.         location = message.find(insert)
  210.         first = message[:location]
  211.         if location == len(message):
  212.             last = ""
  213.         else:
  214.             last = message[location + len(insert):]
  215.         message = first + last
  216.         message = base64.b64decode(message)
  217.         if message.startswith(k.encode('ascii')):
  218.             return str(message)[len(k)+2:-1]
  219.         else:
  220.             raise Exception
  221.     except Exception as e:
  222.         return "ERROR DECRYPTING: " + m + "  " + str(e)
  223.  
  224. def checkSecret(room, user, message):
  225.     if message.raw.find("<msg=\"") == -1: return False
  226.     msg = message.raw.split("<msg=\"")[1]
  227.     msg2 = ""
  228.     p = None
  229.     for char in msg:
  230.         if char == "\"" and p != "\\": break
  231.         if char == "\\":
  232.             if p == "\\": msg2 += char
  233.         else:
  234.             msg2 += char
  235.         p = char
  236.     addMessageR(room, user.name + ": " + secretDecrypt(msg2, user.name.lower()), SECRET)
  237.     return True
  238.  
  239. class RoomManager(ch.RoomManager):
  240.     def onHistoryMessage(self, room, user, message):
  241.         checkSecret(room, user, message)
  242.         addMessageR(room, user.name + ": " + message.body, hexToAnsi(message.fontColor))
  243.         drawFields()
  244.         screen.refresh()
  245.        
  246.     def onMessage(self, room, user, message):
  247.         logMessage(message)
  248.         if checkSecret(room, user, message) or not echo or user.name.lower() != NICK.lower(): addMessageR(room, user.name + ": " + message.body, hexToAnsi(message.fontColor))
  249.         if user.name.lower() in pages.keys():
  250.             for i in pages[user.name.lower()]: room.message("(PAGE) @" + user.name + ": " + i)
  251.             del pages[user.name.lower()]
  252.         curses.beep()
  253.         drawFields()
  254.         screen.refresh()
  255.    
  256.     def onPMMessage(self, pm, user, body):
  257.         addMessageR(room, "@" + NICK + ": " + user.name + ": " + body, NORMAL)
  258.         drawFields()
  259.         screen.refresh()
  260.        
  261.     def onPMDisconnect(self, pm):
  262.         addMessageR(room, "PM disconnect", NORMAL)
  263.         drawFields()
  264.         screen.refresh()
  265.    
  266.     def onLeave(self, room, user):
  267.         addMessageR(room, user.name + " left the room.")
  268.         drawOnline()
  269.         drawFields()
  270.         screen.refresh()
  271.    
  272.     def onJoin(self, room, user):
  273.         addMessageR(room, user.name + " entered the room.")
  274.         drawOnline()
  275.         drawFields()
  276.         screen.refresh()
  277.    
  278.     def onConnect(self, room):
  279.         addMessageR(room, "You have connected to " + room.name + ".")
  280.         drawFields()
  281.         screen.refresh()
  282.  
  283.     def onReconnect(self, room):
  284.         addMessageR(room, "You have reconnected to " + room.name + ".")
  285.         drawFields()
  286.         screen.refresh()
  287.  
  288.     def onFloodWarning(self, room):
  289.         room.reconnect()
  290.    
  291.     def onUserCountChange(self, room):
  292.         drawOnline()
  293.         drawFields()
  294.         screen.refresh()
  295.  
  296. def centerString(string, length):
  297.     off = length - len(string)
  298.     if off > 0:
  299.         l = int(off / 2)
  300.         if off % 2:
  301.             r = l + 1
  302.         else:
  303.             r = l
  304.         return " " * l + string + " " * r
  305.     elif off < 0:
  306.         return string[:length]
  307.  
  308. def leftString(string, length):
  309.     if len(string) > length:
  310.         return string[:length]
  311.     else:
  312.         off = length - len(string)
  313.         return string  + " " * off
  314.  
  315. def rightString(string, length):
  316.     if len(string) > length:
  317.         return string[:length]
  318.     else:
  319.         off = length - len(string)
  320.         return string + off * " "
  321.  
  322. def fieldString(string, length):
  323.     if len(string) > length:
  324.         return string[-length:]
  325.     else:
  326.         off = length - len(string)
  327.         return string + off * " "
  328.  
  329. def fieldLength(string, length):
  330.     if len(string) > length:
  331.         return length
  332.     else:
  333.         return len(string)
  334.  
  335. def drawRooms():
  336.     y = 0
  337.     for y in range(len(chatango.roomnames)):
  338.         if y >= HEIGHT - 2: break
  339.         room = list(chatango.roomnames)[y]
  340.         if chatango.getRoom(room).new:
  341.             attr = curses.color_pair(YELLOW) | curses.A_BOLD
  342.         else:
  343.             attr = curses.color_pair(NORMAL)
  344.         if room == activeRoom.name: attr |= curses.A_REVERSE
  345.         screen.addstr(y + 1, 0, leftString(room, QUARTER), attr)
  346.     if len(chatango.roomnames) > 0: y += 1
  347.     while y < HEIGHT - 2:
  348.         screen.addstr(y + 1, 0, leftString("", QUARTER), curses.color_pair(NORMAL))
  349.         y += 1
  350.  
  351. def drawOnline():
  352.     if not activeRoom:
  353.         users = []
  354.     else:
  355.         users = sorted(activeRoom.usernames)
  356.     y = 0
  357.     for y in range(len(users)):
  358.         if y >= HEIGHT - 2: break
  359.         nick = users[y]
  360.         if activeRoom and activeRoom.activeUser == users[y]:
  361.             attr = curses.color_pair(RED) | curses.A_REVERSE
  362.         else:
  363.             attr = curses.color_pair(NORMAL)
  364.         if nick == activeRoom.name: attr |= curses.A_REVERSE
  365.         screen.addstr(y + 1, HALF + QUARTER, rightString(nick, QUARTER), attr)
  366.     if len(users) > 0: y += 1
  367.     while y < HEIGHT - 2:
  368.         screen.addstr(y + 1, HALF + QUARTER, rightString("", QUARTER), curses.color_pair(NORMAL))
  369.         y += 1
  370.  
  371. def drawChat():
  372.     if not activeRoom:
  373.         chatBuffer = generalBuffer
  374.     else:
  375.         chatBuffer = activeRoom.chatBuffer
  376.     y = 0
  377.     for y in range(len(chatBuffer)):
  378.         if y >= HEIGHT - 3: break
  379.         message = chatBuffer[y]
  380.         screen.addstr(y + 1, QUARTER, leftString(message[0], HALF), curses.color_pair(message[1]))
  381.     if len(chatBuffer) > 0: y += 1
  382.     while y < HEIGHT - 3:
  383.         screen.addstr(y + 1, QUARTER, leftString("", HALF), curses.color_pair(NORMAL))
  384.         y += 1
  385.  
  386. def drawField(y, x, content, width, selected, color=NORMAL):
  387.     attr = curses.color_pair(color)
  388.     if selected: attr |= curses.A_REVERSE
  389.     screen.addstr(y, x, fieldString(content, width), attr)
  390.     if selected:
  391.         return (y, x + fieldLength(content, width))
  392.     else:
  393.         return None
  394.  
  395. def drawFields():
  396.     if activeRoom:
  397.         color = hexToAnsi(chatango.user.fontColor)
  398.     else:
  399.         color = NORMAL
  400.     f1 = drawField(HEIGHT - 1, 0, contents[0], QUARTER - 1, focus == 0)
  401.     f2 = drawField(HEIGHT - 1, QUARTER, contents[1], HALF - 1, focus == 1, color)
  402.     f3 = drawField(HEIGHT - 1, HALF + QUARTER, contents[2], QUARTER - 1, focus == 2, color)
  403.     if f1:
  404.         screen.move(f1[0], f1[1])
  405.     elif f2:
  406.         screen.move(f2[0], f2[1])
  407.     elif f3:
  408.         screen.move(f3[0], f3[1])
  409.        
  410. def drawHeaders():
  411.     screen.addstr(0, 0, centerString("ROOMS", QUARTER), curses.color_pair(NORMAL) | curses.A_REVERSE)
  412.     screen.addstr(0, QUARTER, centerString("CHATANGO", HALF), curses.color_pair(NORMAL) | curses.A_REVERSE)
  413.     screen.addstr(0, HALF + QUARTER, centerString("ONLINE", QUARTER), curses.color_pair(NORMAL) | curses.A_REVERSE)
  414.  
  415. def drawContent():
  416.     drawRooms()
  417.     drawOnline()
  418.     drawChat()
  419.  
  420. def drawInterface():
  421.     drawHeaders()
  422.     drawContent()
  423.     drawFields()
  424.     screen.refresh()
  425.  
  426. def alreadyConnected(room):
  427.     chatango.getRoom(room)
  428.    
  429. def switchRoom(room):
  430.     global activeRoom
  431.     activeRoom = room
  432.     room.new = False
  433.     drawContent()
  434.     drawHeaders()
  435.    
  436. def hide(message, hidden):
  437.     if hidden:
  438.         return "*" * len(message)
  439.     else:
  440.         return message
  441.  
  442. def dialogue(prompt, hidden=False):
  443.     screen.border(0)
  444.     screen.addstr(int(HEIGHT / 2), HALF - len(prompt), prompt)
  445.     screen.refresh()
  446.    
  447.     RESULT = ""
  448.     while True:
  449.         c = screen.getch()
  450.         if c == 10 and RESULT != "":
  451.             RESULT = RESULT.strip()
  452.             break
  453.         elif c == 127:
  454.             if RESULT != "": RESULT = RESULT[:-1]
  455.             screen.addstr(int(HEIGHT / 2), HALF, leftString(hide(RESULT, hidden), HALF))
  456.             screen.border(0)
  457.             screen.move(int(HEIGHT / 2), HALF + len(RESULT))
  458.             screen.refresh()
  459.         elif c == 27:
  460.             curses.endwin()
  461.             sys.exit()
  462.         else:
  463.             if len(RESULT) < HALF - 1:
  464.                 RESULT += chr(c)
  465.                 if hidden:
  466.                     display = "*" * len(RESULT)
  467.                 else:
  468.                     display = RESULT
  469.                 screen.addstr(int(HEIGHT / 2), HALF, leftString(hide(RESULT, hidden), HALF))
  470.                 screen.border(0)
  471.                 screen.move(int(HEIGHT / 2), HALF + len(RESULT))
  472.                 screen.refresh()
  473.    
  474.     screen.erase()
  475.     return RESULT
  476.  
  477. NICK = dialogue("Enter your username: ")
  478. PASS = dialogue("Enter your password: ", True)
  479.  
  480. chatango = RoomManager(NICK, PASS)
  481. chatango._userlistMode = ch.Userlist_All
  482. chatango_thread = threading.Thread(target=chatango.main,)
  483. chatango_thread.setDaemon(True)
  484. chatango_thread.start()
  485. drawInterface()
  486.  
  487. addMessage("Welcome to MegaLoler's Chatango client!\npatch by ASL97 for python 3.x\nJoin a room to get started.")
  488.  
  489. esc = False
  490. while True:
  491.     drawFields() #perhaps make more effient later
  492.     c = screen.getch()
  493.     if c == 10: # Enter
  494.         msg = contents[focus].strip()
  495.         if msg != "":
  496.             contents[focus] = ""
  497.             if focus == 0:
  498.                 r = alreadyConnected(msg)
  499.                 if r == None:
  500.                     chatango.joinRoom(msg)
  501.                     room = chatango.getRoom(msg)
  502.                     room.chatBuffer = []
  503.                     room.activeUser = None
  504.                     room.new = False
  505.                     switchRoom(room)
  506.                 else:
  507.                     switchRoom(r)
  508.             elif focus == 1:
  509.                 if activeRoom:
  510.                     if msg[0] == "/":
  511.                         msg = msg[1:]
  512.                         if msg != "":
  513.                             parts = msg.split(" ")
  514.                             cmd = parts[0].lower()
  515.                             if len(parts) == 1:
  516.                                 pars = []
  517.                             else:
  518.                                 pars = parts[1:]
  519.                             par = " ".join(pars)
  520.                             if cmd == "color":
  521.                                 chatango.setFontColor(par)
  522.                                 drawChat()
  523.                             elif cmd == "namecolor":
  524.                                 chatango.setNameColor(par)
  525.                                 drawOnline()
  526.                             elif cmd == "msg":
  527.                                 activeRoom.message("<msg=\"" + str(secretEncrypt(par, NICK.lower())) + "\"></msg>" + disguise, True)
  528.                             elif cmd == "help":
  529.                                 addMessageR(activeRoom, HELP_MSG)
  530.                             elif cmd == "page":
  531.                                 if len(pars) > 1:
  532.                                     page(pars[0], " ".join(pars[1:]))
  533.                                     addMessageR(activeRoom, "The message will be sent when " + pars[0] + " is next seen.")
  534.                                 else:
  535.                                     addMessageR(activeRoom, "The syntax is /page [user] [message].")
  536.                             elif cmd == "pages":
  537.                                 if par == "":
  538.                                     if len(pages.keys()):
  539.                                         addMessageR(activeRoom, "Pages are queued for the following users: " + ", ".join(pages.keys()) + ".")
  540.                                     else:
  541.                                         addMessageR(activeRoom, "No pages are queued.")
  542.                                 else:
  543.                                     if par.lower() in pages.keys():
  544.                                         addMessageR(activeRoom, "The user " + par + " has the following pages queued:\n" + "\n".join(pages[par.lower()]))
  545.                                     else:
  546.                                         addMessageR(activeRoom, "The user " + par + " does not have any pages queued.")
  547.                             elif cmd == "disguise":
  548.                                 disguise = par
  549.                                 addMessageR(activeRoom, "Disguise set to \"" + disguise + "\".")
  550.                             elif cmd == "clear":
  551.                                 activeRoom.chatBuffer = []
  552.                                 addMessageR(activeRoom, "Cleared the screen.")
  553.                             elif cmd == "raw":
  554.                                 raw = not raw
  555.                                 if raw:
  556.                                     addMessageR(activeRoom, "Raw mode is now ON.")
  557.                                 else:
  558.                                     addMessageR(activeRoom, "Raw mode is now OFF.")
  559.                             elif cmd == "echo":
  560.                                 echo = not echo
  561.                                 if echo:
  562.                                     addMessageR(activeRoom, "Echo mode is now ON.")
  563.                                 else:
  564.                                     addMessageR(activeRoom, "Echo mode is now OFF.")
  565.                             elif cmd == "part":
  566.                                 for i in range(len(chatango._rooms)):
  567.                                     if list(chatango.roomnames)[i] == activeRoom.name: break
  568.                                 chatango.leaveRoom(activeRoom.name)
  569.                                 if len(chatango.roomnames) > 0:
  570.                                     i %= len(chatango.roomnames)
  571.                                     switchRoom(list(chatango.rooms)[i])
  572.                                 else:
  573.                                     activeRoom = None
  574.                                     drawContent()
  575.                                
  576.                             else:
  577.                                 addMessageR(activeRoom, "Commands: /color [color] (sets your font color), /namecolor [color] (sets your name color), /part (disconnect from the current room), /help (get help on how to use this client), /raw (toggles raw mode which allows you to type with html formatting), /clear (clears the screen), /msg [message] (sends a secret message that only special people can see, and the message will appear to others as defined by the /disguise command to obfuscate the fact that you are sending secret messages), /disguise [message] (sets the disguise message for use with the /msg command), /page [user] [message] (queue a message that will be sent when a certain user is seen), /pages (user) (lists any currently queued pages), /echo (toggles echo mode which echos user input immediately rather than waiting for it to echo from the server)")
  578.                     else:
  579.                         activeRoom.message(msg, raw)
  580.                         if echo: addMessageR(activeRoom, NICK + ": " + msg, hexToAnsi(chatango.user.fontColor))
  581.                 else:
  582.                     if msg == "/help":
  583.                         addMessage(HELP_MSG)
  584.                     else:
  585.                         addMessage("You are not connected to any rooms!  Type /help for help.")
  586.             elif focus == 2:
  587.                 if activeRoom and activeRoom.activeUser:
  588.                     chatango.pm.message(ch.User(activeRoom.activeUser), msg)
  589.                     addMessageR(activeRoom, "@" + activeRoom.activeUser + ": " + NICK + ": " + msg, hexToAnsi(chatango.user.fontColor))
  590.             drawFields()
  591.             screen.refresh()
  592.     elif c == 9: # Tab
  593.         focus = (focus + 1) % 3
  594.         drawFields()
  595.         screen.refresh()
  596.     elif c == 96: # `
  597.         if len(chatango.roomnames) > 0:
  598.             for i in range(len(chatango.roomnames)):
  599.                 if list(chatango.roomnames)[i] == activeRoom.name: break
  600.             i = (i + 1) % len(chatango.roomnames)
  601.             switchRoom(list(chatango.rooms)[i])
  602.     elif c == 126: # ~
  603.         if activeRoom:
  604.             if len(activeRoom.usernames) > 0:
  605.                 users = sorted(activeRoom.usernames)
  606.                 for i in range(len(users)):
  607.                     if users[i] == activeRoom.activeUser: break
  608.                 i = (i + 1) % (len(activeRoom.usernames))
  609.                 activeRoom.activeUser = users[i]
  610.                 drawOnline()
  611.     elif c == 127: # Backspace
  612.         if contents[focus] != "": contents[focus] = contents[focus][:-1]
  613.         drawFields()
  614.         screen.refresh()
  615.     elif c == 27: # Esc
  616.         if esc:
  617.             break
  618.         else:
  619.             esc = True
  620.             continue
  621.  
  622.     elif c == 35: # #  \  95 : _
  623.         if activeRoom:
  624.             try:
  625.                 msg = room._history[-1]
  626.                 if msg:
  627.                     room.rawClearUser(msg.unid)
  628.                     drawFields()
  629.                     screen.refresh()
  630.             except:
  631.                 pass
  632.  
  633.     else:
  634.         contents[focus] += chr(c)
  635.         drawFields()
  636.         screen.refresh()
  637.     esc = False
  638.  
  639. chatango.stop()
  640. curses.endwin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement