Esempio n. 1
0
 def _split_reply(self, msg, split, times):
     """Splits a reply into multiple messages.
     
     @arg splitpoint: what pattern is it best to split at?"""
     times += 1
     added_len = len("PRIVMSG %s \n"%self.nick)
     if len(msg) + added_len <= 255:
         self.reply(msg)
     else:
         more_suffix = ""
         if times == config.getint("Bot", "max reply splits before waiting"):
             more_suffix = split \
                 + _("Reply is too long, use \x02%(prefix)smore\x02 to continue reading.")\
                 % {'prefix':config.get('Bot', 'command prefix')}
         added_len += len(more_suffix)
         m = re.match("^(?P<send>.{0,%d})%s(?P<rest>.*?)$"\
             % (255-added_len, re.escape(split)), msg)
         if not m:
             # If we can't split conveniently, cut straight in
             self.reply(msg[:255-added_len]+more_suffix)
             rest = msg[255-added_len:]
         else:
             self.reply(m.group('send')+more_suffix)
             rest = m.group('rest')
         if len(more_suffix):
             t = time()
             self.bot.more_buffer[self.nick] = (rest, t)
             reactor.callLater(60, self._dropMoreBuffer, t)
         else:
             self._split_reply(rest, split, times)
Esempio n. 2
0
        def _knowAdmin(admin):
            if self.last_promote + config.getint('Pickup', 'promote delay') > time() \
                    and not admin:
                raise InputError(_("Can't promote so often."))

            game = self.get_game(call, args)

            if call.nick not in game.players \
                    and not admin:
                raise InputError(_("Join the game yourself before promoting it."))

            self.last_promote = time()
            self.pypickupbot.cmsg(
                config.get('Pickup messages', 'promote').decode('string-escape') % {
                    'bold': '\x02', 'prefix': config.get('Bot', 'command prefix'),
                    'name': game.name, 'nick': game.nick,
                    'command': config.get('Bot', 'command prefix')+'add '+game.nick,
                    'channel': self.pypickupbot.channel,
                    'playersneeded': game.maxplayers-len(game.players),
                    'maxplayers': game.maxplayers, 'numplayers': len(game.players),
                })
Esempio n. 3
0
    def update_topic(self):
        """Update the pickup part of the channel topic"""
        config_topic = config.getint('Pickup', 'topic')

        if not config_topic:
            return

        out = []
        for gamenick in self.order:
            game = self.games[gamenick]
            if config_topic == 1 or game.players:
                out.append(
                    config.get('Pickup messages', 'topic game').decode('string-escape')
                    % {
                        'nick': game.nick, 'playernum': len(game.players),
                        'playermax': game.maxplayers, 'name': game.name,
                        'numcaps': game.caps
                    })

        self.topic.update(
            config.get('Pickup messages', 'topic game separator')\
                .decode('string-escape')\
            .join(out)
            )
Esempio n. 4
0
 def clientConnectionFailed(self, connector, reason):
     delay = config.getint('Bot', 'connect retry delay')
     log.err("Could not connect (%s), trying again in %d seconds." %(reason, delay))
     reactor.callLater(delay, connector.connect)
Esempio n. 5
0
 def clientConnectionLost(self, connector, reason):
     delay = config.getint('Bot', 'reconnect delay')
     log.err("Connection lost (%s), reconnecting in %d seconds." %(reason, delay))
     reactor.callLater(delay, connector.connect)