Browse Source

!urban: Strip out link brackets.

main
Ben Kurtovic 6 years ago
parent
commit
db2f9968fa
1 changed files with 9 additions and 5 deletions
  1. +9
    -5
      commands/urbandictionary.py

+ 9
- 5
commands/urbandictionary.py View File

@@ -16,8 +16,12 @@ class UrbanDictionary(Command):
commands = ["urban", "urbandictionary", "dct", "ud"] commands = ["urban", "urbandictionary", "dct", "ud"]


@staticmethod @staticmethod
def _normalize(word):
return re.sub(r"\W", "", word.lower())
def _normalize_term(term):
return re.sub(r"\W", "", term.lower())

@staticmethod
def _normalize_text(text):
return re.sub(r"\[(.*?)\]", "\\1", re.sub(r"\s+", " ", text))


def process(self, data): def process(self, data):
if not data.args: if not data.args:
@@ -34,15 +38,15 @@ class UrbanDictionary(Command):
return return


result = results[0] result = results[0]
definition = re.sub(r"\s+", " ", result["definition"])
example = re.sub(r"\s+", " ", result["example"])
definition = self._normalize_text(result["definition"])
example = self._normalize_text(result["example"])
url = result["permalink"].rsplit("/", 1)[0] url = result["permalink"].rsplit("/", 1)[0]
if definition and definition[-1] not in (".", "!", "?"): if definition and definition[-1] not in (".", "!", "?"):
definition += "." definition += "."


msg = "{0} \x02Example\x0F: {1} {2}".format( msg = "{0} \x02Example\x0F: {1} {2}".format(
definition.encode("utf8"), example.encode("utf8"), url) definition.encode("utf8"), example.encode("utf8"), url)
if self._normalize(result["word"]) != self._normalize(arg):
if self._normalize_term(result["word"]) != self._normalize_term(arg):
msg = "\x02{0}\x0F: {1}".format(result["word"].encode("utf8"), msg) msg = "\x02{0}\x0F: {1}".format(result["word"].encode("utf8"), msg)


self.reply(data, msg) self.reply(data, msg)

Loading…
Cancel
Save