/[shmookey]/killbot/killbot.py


UCC Code Repository

Diff of /killbot/killbot.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 122 by shmookey, Wed Sep 16 01:39:09 2009 UTC revision 123 by shmookey, Wed Nov 11 02:41:36 2009 UTC
# Line 8  Line 8 
8    
9  import re, os, sys  import re, os, sys
10  import conf, easybot  import conf, easybot
11    import unicodedata
12    
13  BOT_NAME = conf.username  BOT_NAME = conf.username
14    
# Line 19  def load_channel (channel): Line 20  def load_channel (channel):
20                  pattern_file = open ("channels/" + channel, "r")                  pattern_file = open ("channels/" + channel, "r")
21                  for line in pattern_file.read().split("\n"):                  for line in pattern_file.read().split("\n"):
22                          if (not line == "") and (not line[0] == ";"):                          if (not line == "") and (not line[0] == ";"):
23                                  patterns[channel].append( (line,re.compile(line,re.IGNORECASE)) )                                  patterns[channel].append( (line,re.compile(line, re.IGNORECASE | re.UNICODE)) )
24                  pattern_file.close ()                  pattern_file.close ()
25          else:          else:
26                  os.mknod ("channels/" + channel)                  os.mknod ("channels/" + channel)
# Line 35  def msg (chobj, channel, msg_from, msg, Line 36  def msg (chobj, channel, msg_from, msg,
36                          for response in responses:                          for response in responses:
37                                  chobj.privmsg (channel, response)                                  chobj.privmsg (channel, response)
38                          return                          return
39            
40            # strip out all but alphanumeric (Ll, Lu, Nd) and spacing (Zs) characters.
41            # punctuation is deliberately stripped out so as people cannot evade kicks by padding their message
42            safe_chars = [ 'Lu', 'Ll', 'Zs', 'Nd' ]
43            clean_msg = ''.join(c for c in msg.decode('utf-8') if unicodedata.category(c) in safe_chars)
44    
45          for pattern in patterns[channel]:          for pattern in patterns[channel]:
46                  if re.search (pattern[1], msg):                  if re.search (pattern[1], clean_msg):
47                          print "Kicking " + msg_from + " for violating kickable expression (\"" + pattern[0] + "\")"                          print "Kicking " + msg_from + " for violating kickable expression (\"" + pattern[0] + "\")"
48                          chobj.kick (channel, msg_from, "Violating kickable expression (\"" + pattern[0] + "\")")                          chobj.kick (channel, msg_from, "Violating kickable expression (\"" + pattern[0] + "\")")
49    
# Line 47  def process_command (cmd, channel, msg_f Line 53  def process_command (cmd, channel, msg_f
53                  if words[0] == "help":                  if words[0] == "help":
54                          responses = ["I kick people when they act like idiots! Channel operators can define what idiotic behaviour looks like with Python-style regex by telling me:"]                          responses = ["I kick people when they act like idiots! Channel operators can define what idiotic behaviour looks like with Python-style regex by telling me:"]
55                          responses.append (BOT_NAME + ": add kickable_pattern_here")                          responses.append (BOT_NAME + ": add kickable_pattern_here")
56                            responses.append ("I ignore everything except letters, numbers and whitespace when processing the regex.")
57                          responses.append ("Anyone can get the list of kickable expressions by asking me with \"" + BOT_NAME + ": show\"")                          responses.append ("Anyone can get the list of kickable expressions by asking me with \"" + BOT_NAME + ": show\"")
58                          responses.append ("Channel operators can remove expressions from the kicklist with \"" + BOT_NAME + ": remove list_index\"")                          responses.append ("Channel operators can remove expressions from the kicklist with \"" + BOT_NAME + ": remove list_index\"")
59                          responses.append ("I was originally written in 2009 by shmookey for #ucc on irc.ucc.asn.au")                          responses.append ("I was originally written in 2009 by shmookey for #ucc on irc.ucc.asn.au")
# Line 70  def process_command (cmd, channel, msg_f Line 77  def process_command (cmd, channel, msg_f
77                          pattern_file.write ("\n" + pattern)                          pattern_file.write ("\n" + pattern)
78                          pattern_file.close ()                          pattern_file.close ()
79                          responses = ["Added \"" + pattern + "\" to the list of kickable expressions."]                          responses = ["Added \"" + pattern + "\" to the list of kickable expressions."]
80                          responses.append ("Use \"kb: remove " + str (len (patterns[channel])-1) + "\" to remove.")                          responses.append ("Use \"" + BOT_NAME + ": remove " + str (len (patterns[channel])-1) + "\" to remove.")
81                          return responses                          return responses
82                  elif words[0] == "remove" and len(words) > 1:                  elif words[0] == "remove" and len(words) > 1:
83                          if not is_oper:                          if not is_oper:

Legend:
Removed from v.122  
changed lines
  Added in v.123

Managed by UCC Webmasters ViewVC Help
Powered by ViewVC 1.1.26