def welcome(self): time.sleep(0.1) self.send('!NOTE Current users are: ' + string.join(nicklist(), ', ')) messages = countmessages() if messages: self.send('!NOTE There are %d saved messages!!!' % messages)
def command(self, message): #handles command messages if message.startswith("/me "): message = message[4:] self.bcast(" * %s %s" % (self.nick,message), self.nick) elif message == '/list': self.send('!NOTE Current users: ' + string.join(nicklist(), ', ')) elif message.startswith('/to'): targetnick = string.split(message)[0][3:] text = string.join(string.split(message)[1:]) if self.monocast(self.nick, targetnick, text): self.send('!NOTE Error sending PM.') elif message.startswith('/nick'): oldnick = self.nick try: newnick = string.split(message)[1] except IndexError: self.send('!NOTE Missing argument!') return if len(newnick) > 10: newnick = newnick[:10] self.send("!NOTE Nickname truncated to %s" % newnick) if changenick(oldnick, newnick) > 0: #if there is an error self.send("!NOTE Nickname could not be changed!") return self.nick = newnick self.bcast(' * The user %s is now known as %s' % (oldnick, self.nick), 'tehsrvr') elif message == '/exit': self.send('!TERMINATE') elif message == '/PONG': #system use only self.pingtime = 0 #messageboard commands elif message == '/msglist': self.send('!NOTE Messages: '+listmessages()) elif message.startswith('/msgpost '): try: wordlist = string.split(message) title = wordlist[1] text = string.join(wordlist[2:]) except: self.send('!NOTE Error parsing request: '+str(sys.exc_info()[1])+'\nYou might want to report this to the server operator.') return self.send("!NOTE "+postmessage(title, text, self.nick)) elif message.startswith('/msgread '): try: title = string.split(message)[1] except IndexError: self.send('!NOTE Missing argument!') return self.send("!NOTE "+readmessage(title)) elif message.startswith('/msgdel '): try: title = string.split(message)[1] except IndexError: self.send('!NOTE Missing argument!') return self.send("!NOTE "+delmessage(title)) else: #not a known command self.send("!NOTE Command not valid.")
def command(self, message): #handles command messages if message.startswith("/me "): message = message[4:] self.bcast(" * %s %s" % (self.nick, message), self.nick) elif message == '/list': self.send('!NOTE Current users: ' + string.join(nicklist(), ', ')) elif message.startswith('/to'): targetnick = string.split(message)[0][3:] text = string.join(string.split(message)[1:]) if self.monocast(self.nick, targetnick, text): self.send('!NOTE Error sending PM.') elif message.startswith('/nick'): oldnick = self.nick try: newnick = string.split(message)[1] except IndexError: self.send('!NOTE Missing argument!') return if len(newnick) > 10: newnick = newnick[:10] self.send("!NOTE Nickname truncated to %s" % newnick) if changenick(oldnick, newnick) > 0: #if there is an error self.send("!NOTE Nickname could not be changed!") return self.nick = newnick self.bcast( ' * The user %s is now known as %s' % (oldnick, self.nick), 'tehsrvr') elif message == '/exit': self.send('!TERMINATE') elif message == '/PONG': #system use only self.pingtime = 0 #messageboard commands elif message == '/msglist': self.send('!NOTE Messages: ' + listmessages()) elif message.startswith('/msgpost '): try: wordlist = string.split(message) title = wordlist[1] text = string.join(wordlist[2:]) except: self.send( '!NOTE Error parsing request: ' + str(sys.exc_info()[1]) + '\nYou might want to report this to the server operator.') return self.send("!NOTE " + postmessage(title, text, self.nick)) elif message.startswith('/msgread '): try: title = string.split(message)[1] except IndexError: self.send('!NOTE Missing argument!') return self.send("!NOTE " + readmessage(title)) elif message.startswith('/msgdel '): try: title = string.split(message)[1] except IndexError: self.send('!NOTE Missing argument!') return self.send("!NOTE " + delmessage(title)) else: #not a known command self.send("!NOTE Command not valid.")