home · contact · privacy
In Markov text generation, lowercase earlier.
[plomlombot-irc.git] / plomlombot.py
index 9197592a3b4b0bac187dac48ed20cbc741ddf5f6..82f96a21e4c93b7371ef1669f749fd73c96afde0 100755 (executable)
@@ -13,6 +13,8 @@ import hashlib
 import os
 import plomsearch
 
+URLREGEX = "(https?://[^\s>]+)"
+
 # Defaults, may be overwritten by command line arguments.
 SERVER = "irc.freenode.net"
 PORT = 6667
@@ -183,11 +185,14 @@ def handle_command(command, argument, notice, target, session):
             shuffle(usable_selections)
             return usable_selections[0][select_length]
 
-        def purge_present_users(tokens):
+        def purge_undesired(tokens):
+            for token in tokens:
+                if None != re.match("^" + URLREGEX, token):
+                    del(tokens[tokens.index(token)])
             for name in session.uses_in_chan:
                 while True:
                     try:
-                        del(tokens[tokens.index(name)])
+                        del(tokens[tokens.index(name.lower())])
                     except ValueError:
                         break
             return tokens
@@ -202,9 +207,9 @@ def handle_command(command, argument, notice, target, session):
         file.close()
         tokens = []
         for line in lines:
-            line = line.replace("\n", "")
+            line = line.replace("\n", "").lower()
             tokens += line.split()
-        tokens = purge_present_users(tokens)
+        tokens = purge_undesired(tokens)
         if len(tokens) <= select_length:
             notice("NOT ENOUGH TEXT TO MARKOV.")
             return
@@ -225,7 +230,7 @@ def handle_command(command, argument, notice, target, session):
             for i in range(select_length - 1):
                 snippet[i] = snippet[i + 1]
             snippet[select_length - 1] = new_end
-        notice(msg.lower() + "malkovich.")
+        notice(msg + "malkovich.")
 
     if "addquote" == command:
         addquote()
@@ -288,7 +293,7 @@ class Session:
                 def notice(msg):
                     self.io.send_line("NOTICE " + target + " :" + msg)
 
-                matches = re.findall("(https?://[^\s>]+)", msg)
+                matches = re.findall(URLREGEX, msg)
                 for i in range(len(matches)):
                     handle_url(matches[i], notice)
                 if "!" == msg[0]: