Ejemplo n.º 1
0
 def projects(self):
     """Reply with all the projects found in the database. Usage: project.projects [user]."""
     if self.args:
         users = [self.userModule._getUser(self.args)]
     else:
         users = self.userModule._users()
     projectsNotFound = True
     if users is not None:
         for user in users:
             projects = self._projects(user[0])
             if projects:
                 self.reply("Owner: %s" % util.toUnicode(user[1]))
             i = 1
             for project in projects:
                 tree = '|-'
                 if i == len(projects):
                     tree = "'-"
                 self.reply(
                     "  %s Project Name: %s" % (
                         tree,
                         util.toUnicode(project[2])
                     )
                 )
                 projectsNotFound = False
                 i += 1
     if projectsNotFound:
         self.reply("No projects has been created yet! D: ...")
Ejemplo n.º 2
0
 def parse(self):
     """
     Read the data from the socket, split it by \r\n and send it to the
     parseData() method.
     
     """
     while True:
         try:
             # if the last element in the split isn't a '', then it didn't
             # end on a \r\n.
             stream = util.toUnicode(self.sock.recv(4096)).split('\r\n')
             for data in stream:
                 util.write(data)
                 self.parseData(data)
             time.sleep(0.1)
         except (socket.timeout, socket.error, BreakOutOfLoop):
             self.server.connect = False
             break
         except (KeyboardInterrupt, SystemExit):
             self.commandHandler.replyWithMessage('Shutting down the bot')
             self.server.connect = False
             break
         except UnicodeDecodeError:
             continue
         except UnicodeEncodeError:
             continue
Ejemplo n.º 3
0
 def users(self):
     """Reply with all the users found in the database. Usage: user.users."""
     noUsers = True
     for user in self._users():
         self.reply("id: %s, user: %s" % (
                 user[0], 
                 util.toUnicode(user[1])
             )
         )
         noUsers = False
     if noUsers:
         self.reply("There are no users yet!...")
Ejemplo n.º 4
0
 def replyWithMessage(self, text, msgType=None):
     """Send a message to the channel from which we received the command."""
     text = util.toUnicode(text)
     recipient = self.user
     if self.channel.startswith("#"):
         recipient = self.channel
     if msgType is None:
         msgType = self.msgType
     # Avoid flooding of a channel
     splitText = text.split("\n")
     timeout = 0.2
     if len(splitText) > 10:
         timeout = 0.5
     for txt in splitText:
         txt = "%s %s :%s\r\n" % (msgType, recipient, txt)
         util.write(txt)
         self.sock.send(util.toBytes(txt))
         time.sleep(timeout)
Ejemplo n.º 5
0
 def test_that_toUnicode_converts_bytes_to_unicode(self):
     testString = bytes("This is a string")
     newString = util.toUnicode(testString)
     self.assertEqual(type(newString), str)