Ejemplo n.º 1
0
        def _gotItem(item, length):
            if args and length == None:
                try:
                    length = timediff_from_str(args.pop(0))
                except InvalidTimeDiffString as e:
                    raise InputError(str(e))
            elif length == None:
                length = config.getduration(
                    self.name.capitalize(), 'default duration')
            item.length = length

            if args:
                item.meta['reason'] = ' '.join(args)

            applied = self.retrieve_real_list().addCallback(item.check_applied)
            def _applied(applied):
                if new:
                    self.listed.append(item)
                    synced = item.sync_with_self()
                else:
                    synced = item.update_db()
                def _reply(self):
                    if new:
                        call.reply(_("{item} created.").format(item=item).capitalize())
                    else:
                        call.reply(_("{item} edited.").format(item=item).capitalize())
                synced.addCallback(_reply)
            applied.addCallback(_applied)

            return item
Ejemplo n.º 2
0
    def purgeGames(self, call, args):
        """!purgegames [keep]

        Purges the played games list from entries recorded earlier than
        [keep] ago. Uses !top10 spread otherwise if [keep] isn't
        provided."""
        if len(args):
            try:
                keep = timediff_from_str(' '.join(args))
            except InvalidTimeDiffString as e:
                raise InputError(e)
        else:
            keep = config.getduration("Pickup player tracking", "top10 spread")
        d = call.confirm(
            "This will delete the record of every game started earlier than {0}, continue?".format(str_from_timediff(keep))
            )
        def _confirmed(ret):
            if ret:
                def done(*args):
                    call.reply("Done.")
                self._purge(keep).addCallback(done)
            else:
                call.reply("Cancelled.")
        d.addCallback(_confirmed)
Ejemplo n.º 3
0
def getduration(section, option):
    s = _parser.get(section, option)
    return timediff_from_str(s)
Ejemplo n.º 4
0
    def mainCmd(self, call, args):
        """!%(name)s [#id|hostmask|user [length [reason]]]
        
        Sets a new %(name)s or edits an existing one."""
        length = None
        needle = None

        if args:
            needle = args.pop(0)
            r = self.search( needle, self.search_keys,
                self.get_cmp_funcs(),
                lambda item: not self.ItemClass.expired(item) )
        else:
            r = []

        if r:
            new = False
            if len(r) > 1:
                call.reply(
                    _("More than one match: please specify the id of the item to edit"))
                return
            else:
                item_ = r[0]

                if 'edited_by' not in item_.meta:
                    item_.meta['edited_by'] = []
                item_.meta['edited_by'].append(call.user)

                try:
                    newlen = timediff_from_str(args[0])
                except IndexError:
                    raise InputError(_("Please specify a new {type} length or reason.").format(type=self.name))
                except InvalidTimeDiffString:
                    length = item_.length
                    # assume it's a new reason for the ban
                else:
                    # apply the new length as if the ban started now without changing start time
                    length = itime() - item_.start + newlen
                    args.pop(0)

                item = defer.succeed(item_)
        else:
            new = True
            if args or needle:
                args.insert(0, needle)
                try:
                    length = timediff_from_str(args[1])
                except (InvalidTimeDiffString, IndexError):
                    # Ignore error and let subclass decide the default value for this
                    pass
                else:
                    del args[1]

            def _newItem(item):
                item.meta['author'] = call.user
                return item
            item = self.ItemClass.from_call(self, call, args)
            item.addCallback(_newItem)

        def _gotItem(item, length):
            if args and length == None:
                try:
                    length = timediff_from_str(args.pop(0))
                except InvalidTimeDiffString as e:
                    raise InputError(str(e))
            elif length == None:
                length = config.getduration(
                    self.name.capitalize(), 'default duration')
            item.length = length

            if args:
                item.meta['reason'] = ' '.join(args)

            applied = self.retrieve_real_list().addCallback(item.check_applied)
            def _applied(applied):
                if new:
                    self.listed.append(item)
                    synced = item.sync_with_self()
                else:
                    synced = item.update_db()
                def _reply(self):
                    if new:
                        call.reply(_("{item} created.").format(item=item).capitalize())
                    else:
                        call.reply(_("{item} edited.").format(item=item).capitalize())
                synced.addCallback(_reply)
            applied.addCallback(_applied)

            return item
 
        return item.addCallback(_gotItem, length)