Пример #1
0
def setup(self):
    self.alias_tentative = {}
    self.fooled = False
    try:
        f = open(filename(self, "karma"), "r")
        self.karmas = pickle.load(f)  # TODO: after the upgrade change to:
        # version, self.karmas = pickle.load
        f.close()
        # TODO: and then get rid of this upgrade code
        try:
            self.karmas[0]
        except KeyError:  # old version
            temp = {}
            for key, karma in self.karmas.items():
                temp[key] = KarmaNode()
                temp[key].karma = karma
            self.karmas = temp
            try:
                f = open(filename(self, "karma_contrib"), "r")
                kcont = pickle.load(f)
                f.close()
                for k, (plus, minus) in kcont.items():
                    kn = self.karmas.setdefault(k, KarmaNode())
                    kn.contrib_plus = plus
                    kn.contrib_minus = minus
            except IOError:
                pass
            save_karma(self)
        else:
            version, self.karmas = self.karmas  # TODO: yell (or upgrade) on version mismatch
    except IOError:
        pass
    klist = list(self.karmas)
    self.fools_dict = dict(zip(klist, klist[1:] + [klist[0]]))
Пример #2
0
def save_quotes(self):
    try:
        f = open(filename(self, "quotes"), "w")
        pickle.dump((QVERSION, self.quotes), f)
        f.close()
    except IOError:
        pass
Пример #3
0
def setup(self):
    self.logs = []
    self.quotes = {}
    try:
        f = open(filename(self, "quotes"), "r")
        num, self.quotes = pickle.load(f)
        f.close()
    except IOError:
        pass
    upgrade(self, num)
Пример #4
0
def save_karma(self):
    if self.fooled and not is_fools():
        for nick, node in self.karmas.items():
            del node.fools_talk
        self.fooled = False
    try:
        f = open(filename(self, "karma"), "w")
        pickle.dump((KVERSION, self.karmas), f)
        f.close()
    except IOError:
        pass