Advertisement
Algabe

clones.py

Sep 9th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.39 KB | None | 0 0
  1. #!/usr/bin/python
  2. # coding:utf8
  3.  
  4. import xchat
  5.  
  6. __module_name__ = "clones"
  7. __module_version__ = "1.0"
  8. __module_description__ = "Muestra antiguos nicks y muestra clones, permite expulsarlos"
  9.  
  10. xchat.emit_print("Channel Message", "\x02\x033"+__module_name__+"\x0f", "cargado.")
  11.  
  12. users = {}
  13. MaxClones = 2
  14. KickReason = "Demasiados clones"
  15.  
  16. def Update_cb(userdata=None):
  17.    
  18.     global users
  19.    
  20.     try:
  21.         for chan in xchat.get_list("channels"):
  22.             c = chan.channel.lower()
  23.             if not c.startswith("#"):
  24.                 continue
  25.             if not c in users:
  26.                 users[c] = {}
  27.             if not "on" in users[c]:
  28.                 users[c]["on"] = []
  29.             context = xchat.find_context(channel=c)
  30.             if context:
  31.                 for user in context.get_list("users"):
  32.                     host = user.host.split("@")[1].lower()
  33.                     nick = user.nick.lower()
  34.                     if host in users[c]:
  35.                         if not nick in users[c][host]:
  36.                             users[c][host].append(nick)
  37.                     else:
  38.                         users[c][host] = [nick]
  39.                     if not nick in users[c]["on"]:
  40.                         users[c]["on"].append(nick)
  41.     except:
  42.         pass
  43.    
  44.     return 1
  45.  
  46. Update_cb()
  47.  
  48. def Clones_cb(word, word_eol, userdata):
  49.    
  50.     chan = xchat.get_info("channel").lower()
  51.     clones = []
  52.    
  53.     if not chan in users:
  54.         return xchat.EAT_XCHAT
  55.    
  56.     xchat.emit_print("Channel Message", __module_name__, "Clones en \02%s\02:" % chan)
  57.    
  58.     for host in users[chan].keys():
  59.         if host == "on": continue
  60.         if len(users[chan][host]) > 1:
  61.             for user in users[chan][host]:
  62.                 if user in users[chan]["on"]:
  63.                     if not user in clones:
  64.                         clones.append(user)
  65.             if len(clones) > 1:
  66.                 xchat.emit_print("Channel Message",
  67.                                  __module_name__,
  68.                                  "  \02*!*@%s\02: %s" % (host, ', '.join(clones)))
  69.         clones = []
  70.                    
  71.     return xchat.EAT_XCHAT
  72.  
  73. def kbClones_cb(word, word_eol, userdata):
  74.    
  75.     chan = xchat.get_info("channel").lower()
  76.     kusers = []
  77.    
  78.     for host in users[chan].keys():
  79.         if host == "on": continue
  80.         if len(users[chan][host]) > MaxClones:
  81.             for user in users[chan][host]:
  82.                 if user in users[chan]["on"]:
  83.                     kusers.append(user)
  84.             if len(kusers) > MaxClones:
  85.                 xchat.command("ban *!*@%s" % host)
  86.                 for user in kusers:
  87.                     xchat.command("kick %s %s" % (user, KickReason))
  88.         kusers = []
  89.                    
  90.     return xchat.EAT_XCHAT
  91.  
  92. def kClones_cb(word, word_eol, userdata):
  93.    
  94.     chan = xchat.get_info("channel").lower()
  95.     kusers = []
  96.    
  97.     for host in users[chan].keys():
  98.         if host == "on": continue
  99.         if len(users[chan][host]) > MaxClones:
  100.             for user in users[chan][host]:
  101.                 if user in users[chan]["on"]:
  102.                     kusers.append(user)
  103.             if len(kusers) > MaxClones:
  104.                 for user in kusers:
  105.                     xchat.command("kick %s %s" % (user, KickReason))
  106.         kusers = []
  107.        
  108.     return xchat.EAT_XCHAT
  109.  
  110. def Join_cb(word, word_eol, userdata):
  111.     global users
  112.    
  113.     nick = word[0][1:].split("!")[0].lower()
  114.     host = word[0].split("@")[1].lower()
  115.     chan = word[2].lstrip(":").lower()
  116.    
  117.     if nick == xchat.get_info("nick").lower():
  118.         return xchat.EAT_NONE
  119.    
  120.     if not chan in users:
  121.         users[chan] = {}
  122.    
  123.     if not "on" in users[chan]:
  124.         users[chan]["on"] = []
  125.    
  126.     if host in users[chan]:
  127.         cnicks = []
  128.         for n in users[chan][host]:
  129.             if n == nick: continue
  130.             if n in users[chan]["on"]:
  131.                 cnicks.append("\x0319%s\x03" % n)
  132.             else:
  133.                 cnicks.append("\x034%s\x03" % n)
  134.         if cnicks:
  135.             context = xchat.find_context(channel=chan)
  136.             context.emit_print("Channel Message",
  137.                              __module_name__,
  138.                              "Nicks usados por %s: %s" % (nick, ', '.join(cnicks)))
  139.             if not nick in users[chan][host]:
  140.                 users[chan][host].append(nick)
  141.     else:
  142.         users[chan][host] = [nick]
  143.    
  144.     if not nick in users[chan]["on"]:
  145.         users[chan]["on"].append(nick)
  146.    
  147.     return xchat.EAT_NONE
  148.  
  149. def Part_cb(word, word_eol, userdata):
  150.     global users
  151.    
  152.     nick = word[0][1:].split("!")[0].lower()
  153.     chan = word[2].lower()
  154.    
  155.     if chan in users and "on" in users[chan] and nick in users[chan]["on"]:
  156.         users[chan]["on"].remove(nick)
  157.    
  158.     return xchat.EAT_NONE
  159.  
  160. def Quit_cb(word, word_eol, userdata):
  161.     global users
  162.    
  163.     nick = word[0][1:].split("!")[0].lower()
  164.  
  165.     for chan in users.keys():
  166.         if nick in users[chan]["on"]:
  167.             users[chan]["on"].remove(nick)
  168.    
  169.     return xchat.EAT_NONE
  170.  
  171. def Kick_cb(word, word_eol, userdata):
  172.     global users
  173.        
  174.     nick = word[3].lower()
  175.     chan = word[2].lower()
  176.    
  177.     if chan in users and "on" in users[chan] and nick in users[chan]["on"]:
  178.         users[chan]["on"].remove(nick)
  179.    
  180.     return xchat.EAT_NONE
  181.  
  182. def Nick_cb(word, word_eol, userdata):
  183.     global users
  184.        
  185.     old = word[0][1:].split("!")[0].lower()
  186.     host = word[0].split("@")[1].lower()
  187.     new = word[2].lstrip(":").lower()
  188.        
  189.     for chan in users.keys():
  190.         if "on" in users[chan] and old in users[chan]["on"]:
  191.             users[chan]["on"].remove(old)
  192.             users[chan]["on"].append(new)
  193.         if host in users[chan]:
  194.             if not new in users[chan][host]:
  195.                 users[chan][host].append(new)
  196.        
  197.    
  198.     return xchat.EAT_NONE
  199.  
  200. def unload_cb(userdata):
  201.     xchat.emit_print("Channel Message", "\x02\x034"+__module_name__+"\x0f", "descargado.")
  202.  
  203. xchat.hook_server("JOIN", Join_cb)
  204. xchat.hook_server("PART", Part_cb)
  205. xchat.hook_server("QUIT", Quit_cb)
  206. xchat.hook_server("KICK", Kick_cb)
  207. xchat.hook_server("NICK", Nick_cb)
  208. xchat.hook_timer(5000, Update_cb)
  209. xchat.hook_command("CLONES", Clones_cb)
  210. xchat.hook_command("KCLONES", kClones_cb)
  211. xchat.hook_command("KBCLONES", kbClones_cb)
  212. xchat.hook_unload(unload_cb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement