def ListFactoids(start=True): """ Update the list of the factoids. """ global factoids, conf f = open('plugins/factoids/data/factoids.txt', 'ab+') if start: factoids = pickle.loads(f.read()) else: os.remove('plugins/factoids/data/factoids.txt') f = open('plugins/factoids/data/factoids.txt', 'ab+') f.write(pickle.dumps(factoids)) f.flush() f.close() for f in factoids: add_help(f, "pub")
def factoids_add(connection, msg, chan, nick): """ Add a factoid. """ global factoids if len(msg) >= 3: factoid = msg[1] message = ' '.join(msg[2:]) if factoid in factoids: # If the command already exists. connection.privmsg(nick, 'Factoid {0} already exists! Try @factoids remove {0} .'.format(factoid)) else: factoids[factoid] = message ListFactoids(False) connection.privmsg(nick, 'Success') add_help(factoid, "pub") else: connection.privmsg(nick, 'Usage: @factoids add <command> <message>')