def handler(self, **args): """adds a factoid link""" from irclib import Event target = self.return_to_sender(args) # Strip the bots name text = self.strip_words(args["text"], 1) linkfrom, dummy, linktype, linkto = self.rMatch.match(text).groups() linkfrom = linkfrom.strip() linktype = linktype.strip() linkto = linkto.strip() weight = 100 if linktype.find("*") != -1: linktype, weight = linktype.split("*", 1) try: weight = int(weight) if weight < 0: weight = 0 elif weight > 1000: weight = 1000 except ValueError: weight = 100 # Check and make sure the factoid isn't there for factoid_key in [linkfrom, linktype, linkto]: if not FactoIds.exists(factoid_key): message = "Factoid \"%s\" must be defined first." % factoid_key return Event("privmsg", "", target, [ message ]) FactoIds.link(linkfrom, linkto, linktype, weight, args["source"]) FactoIds.link(linkto, linkfrom, linktype, weight, args["source"]) return Event("privmsg", "", target, [ "ok" ])
def handler(self, **args): """adds a factoid link""" from irclib import Event target = self.return_to_sender(args) # Strip the bots name text = self.strip_words(args["text"], 1) linkfrom, dummy, linktype, linkto = self.rMatch.match(text).groups() linkfrom = linkfrom.strip() linktype = linktype.strip() linkto = linkto.strip() weight = 100 if linktype.find("*") != -1: linktype, weight = linktype.split("*", 1) try: weight = int(weight) if weight < 0: weight = 0 elif weight > 1000: weight = 1000 except ValueError: weight = 100 # Check and make sure the factoid isn't there for factoid_key in [linkfrom, linktype, linkto]: if not FactoIds.exists(factoid_key): message = "Factoid \"%s\" must be defined first." % factoid_key return Event("privmsg", "", target, [message]) FactoIds.link(linkfrom, linkto, linktype, weight, args["source"]) FactoIds.link(linkto, linkfrom, linktype, weight, args["source"]) return Event("privmsg", "", target, ["ok"])
def handler(self, **args): """adds a factoid""" from irclib import Event target = self.return_to_sender(args) # Strip the bots name text = self.strip_words(args["text"], 1) # Figure out what to split the string on -- _is_ and _are_ can be used # to force the split at a certain point, instead of the first "is" or # "are" if text.find(" _is_ ") != -1: splitString = " _is_ " elif text.find(" _are_ ") != -1: splitString = " _are_ " elif text.find(" is ") != -1: splitString = " is " elif text.find(" are ") != -1: splitString = " are " # Separate the text into two parts, one is the factoid key (before # "is"), one is the factoid value. "foo is bar" will result in foo # being the key and bar being the value. Also, many is's will get # joined together in the factoid value, the first is separates the key # from the value data = text.split(splitString, 1) # only split once factoid_key = self.strip_punctuation(data[0]) factoid_value = data[1] msg = "ok" if len(factoid_key) > self.FACTOID_KEY_LENGTH: old_key = factoid_key factoid_key = factoid_key[:self.FACTOID_KEY_LENGTH] msg = "WARNING: The factoid key '" + old_key + "' is" + \ " too long, using this truncated key '" + factoid_key + \ "' instead." # Check and make sure the factoid isn't there if FactoIds.exists(factoid_key): message = "Factoid \"%s\" already exists." % factoid_key return Event("privmsg", "", target, [ message ]) FactoIds.add(factoid_key, factoid_value, args["source"]) return Event("privmsg", "", target, [ msg ])
def handler(self, **args): """adds a factoid""" from irclib import Event target = self.return_to_sender(args) # Strip the bots name text = self.strip_words(args["text"], 1) # Figure out what to split the string on -- _is_ and _are_ can be used # to force the split at a certain point, instead of the first "is" or # "are" if text.find(" _is_ ") != -1: splitString = " _is_ " elif text.find(" _are_ ") != -1: splitString = " _are_ " elif text.find(" is ") != -1: splitString = " is " elif text.find(" are ") != -1: splitString = " are " # Separate the text into two parts, one is the factoid key (before # "is"), one is the factoid value. "foo is bar" will result in foo # being the key and bar being the value. Also, many is's will get # joined together in the factoid value, the first is separates the key # from the value data = text.split(splitString, 1) # only split once factoid_key = self.strip_punctuation(data[0]) factoid_value = data[1] msg = "ok" if len(factoid_key) > self.FACTOID_KEY_LENGTH: old_key = factoid_key factoid_key = factoid_key[:self.FACTOID_KEY_LENGTH] msg = "WARNING: The factoid key '" + old_key + "' is" + \ " too long, using this truncated key '" + factoid_key + \ "' instead." # Check and make sure the factoid isn't there if FactoIds.exists(factoid_key): message = "Factoid \"%s\" already exists." % factoid_key return Event("privmsg", "", target, [message]) FactoIds.add(factoid_key, factoid_value, args["source"]) return Event("privmsg", "", target, [msg])