Example #1
0
 def log(self, message):
     current_time = time.time()
     if current_time >= self.rollat:
         self.roll()
     t = time.localtime(int(current_time))
     timestamp = time.strftime(_("[%H:%M:%S]"), time.localtime(time.time()))
     msg = _("%(timestamp)s %(message)s\n") % {'timestamp': timestamp, 'message': to_unicode(message)}
     self.file.write(msg.encode("UTF-8"))
     self.file.flush()
Example #2
0
 def privmsg(self, user, channel, msg):
     """This will get called when the bot receives a message."""
     # 'user' has the form 'nickname!username@host'
     user = user.split('!', 1)[0]
     str = _("(%(user)s) %(msg)s") % {'user': to_unicode(user), 'msg': self.u_(msg, channel)}
     self.logger.log(channel, str)
     # The message may be one of the bot's commands if it contains ! as one of its characters
     if '!' in msg:
         m = self.message_rex.match(msg)
         if m:
             self.words_callback(m.group('command'), channel, user, m.group('args'))
Example #3
0
 def userQuit(self, user, quitMessage):
     """This gets called when a user quits the network"""
     # The user is not in the channel anymore
     for channel in self.channels():
         channel = str(channel)
         try:
             del self.usermodes[channel][user]
         except KeyError:
             # The user was not in this channel.
             pass
         else:
             self.logger.log(channel, _("-!- %(user)s has quit (%(quitMessage)s)") % {'user': user, 'quitMessage': to_unicode(quitMessage)})
Example #4
0
    def to_unicode_with_channel_enc(self, txt, channel):
        """Tries to decode the string txt into an unicode object, trying channel encoding"""
        enc = getattr(self.channels(channel), 'encoding', 'ISO-8859-15')

        return to_unicode(txt, 'UTF-8', (enc, 'ISO-8859-15'))
Example #5
0
 def to_encoding(self, txt, enc="ISO8859-15"):
     """Returns the text 'txt', safely encoded to the encoding 'enc', by guessing the source encoding"""
     return to_unicode(txt).encode(enc)