Advertisement
nucular

nucbot 1.0

Feb 23rd, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.37 KB | None | 0 0
  1. __module_name__ = "nucbot"
  2. __module_version__ = "1.0"
  3. __module_description__ = "An experimental bot script by nucular, made for HexChat 2.9.4"
  4.  
  5. print __module_name__, __module_version__,"has been loaded\003"
  6. print __module_description__
  7.  
  8. import xchat
  9. import io
  10. import fnmatch
  11. import random
  12. import subprocess
  13. import socket
  14. import httplib
  15.  
  16. global s
  17. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  18.  
  19. def check(host):
  20.     try:
  21.         s.connect((host,80))
  22.         ret = host + " seems to be up from here."
  23.     except:
  24.         ret = host + " seems to be down from here."
  25.     s.close()
  26.     return ret
  27.  
  28.  
  29. api_key = "21246044e6856574301dfce647137e959737e8b4de9416a5141056aafae1a4a2"
  30. import pyipinfodb
  31.  
  32. tracer = pyipinfodb.IPInfo(api_key)
  33.  
  34. mynick = xchat.get_info('nick')
  35.  
  36. # shortcut for pattern matching
  37. def match(one,two):
  38.     return fnmatch.fnmatch(one,two)
  39.  
  40. def gethost(nick):
  41.     list = xchat.get_list("users")
  42.     nicklist = []
  43.     for i in list:
  44.         nicklist = nicklist + [i.nick]
  45.     return list[nicklist.index(nick)].host
  46.  
  47. def getprefix(nick):
  48.     list = xchat.get_list("users")
  49.     nicklist = []
  50.     for i in list:
  51.         nicklist = nicklist + [i.nick]
  52.     return list[nicklist.index(nick)].prefix
  53.  
  54. # load admin list; set shortcuts
  55. # TODO: use host mask because safer
  56. global admins
  57. admins = xchat.get_pluginpref("nucbot-admins")
  58. if admins == None:
  59.     xchat.set_pluginpref("nucbot-admins", list())
  60.     admins = list()
  61.  
  62. def isadmin(nick):
  63.     return nick == "nucular_"
  64. def setadmin(nick):
  65.     admins = admins + [nick]
  66.     xchat.set_pluginpref("nucbot-admins", admins)
  67. def removeadmin(nick):
  68.     if nick in admins:
  69.         admins.remove(nick)
  70.         xchat.set_pluginpref("nucbot-admins", admins)
  71.  
  72.  
  73. # create hook list for panic
  74. global hooks
  75. hooks = list()
  76.  
  77. def eat(nick):
  78.     xchat.command("me eats " + nick)
  79.    
  80. def decide(ways):
  81.     rndm = random.randrange(0,len(ways))
  82.     return ways[rndm]
  83.    
  84. def ignore(trignick,host):
  85.     xchat.command("ignore "+host)
  86.     xchat.command("me ignores "+trignick)
  87.    
  88. def unignore(trignick,host):
  89.     xchat.command("unignore "+host)
  90.     xchat.command("me stops ignoring "+trignick)
  91.  
  92. # Main things
  93. def main(word, word_eol, userdata):
  94.     trignick = word[0]
  95.     trigmsg = word[1]
  96.     msg = trigmsg.split(" ")
  97.     cmd = msg[1]
  98.     args = msg[2:len(msg)]
  99.     args_str = ""
  100.     for i in args:
  101.         args_str = args_str + i + " "
  102.         args_str = args_str[0:len(args_str)-1]
  103.        
  104.     if cmd == "eat":
  105.         if not args_str == "":
  106.             eat(args_str)
  107.         else:
  108.             xchat.command("notice "+trignick+" Usage: eat <something>")
  109.            
  110.     elif cmd == "ignore":
  111.         if isadmin(trignick):
  112.             ignore(args_str,args_str)
  113.         else:
  114.             xchat.command("notice "+trignick+" You're not admin!")
  115.            
  116.     elif cmd == "unignore":
  117.         if isadmin(trignick):
  118.             unignore(args_str,args_str)
  119.         else:
  120.             xchat.command("notice "+trignick+" You're not admin!")
  121.            
  122.     elif cmd == "isadmin":
  123.         if isadmin(args_str):
  124.             xchat.command("say " + args_str + " is one of my admins.")
  125.         else:
  126.             xchat.command("say " + args_str + " is not my admin.")
  127.            
  128.     elif cmd == "decide":
  129.         if not len(args)<2:
  130.             xchat.command("say I would say... " + decide(args) + ".")
  131.         elif len(args) == 0:
  132.             xchat.command("notice " + trignick + " Usage: decide <way1> <way2> <...>")
  133.         elif len(args) == 1:
  134.             xchat.command("say I think, you can decide this by yourself.")
  135.            
  136.     elif cmd == "tracenick":
  137.         try:
  138.             things = tracer.GetCity(gethost(args_str).split("@")[1])
  139.             country = things["CountryName"]
  140.             region = things["RegionName"]
  141.             long = things["Longitude"]
  142.             lat = things["Latitude"]
  143.             if country == "":
  144.                 xchat.command("say No useful tracing possible.")
  145.             else:
  146.                 xchat.command("say Country: "+country+"    Region: "+region + "    Longitude: " + long + "    Latitude: " + lat)
  147.         except:
  148.             xchat.command("say No useful tracing possible.")
  149.            
  150.     elif cmd =="gethost":
  151.         xchat.command("say " + args_str + "'s host is " + gethost(args_str))
  152.    
  153.     elif cmd == "check":
  154.         xchat.command("say "+ check(args_str))
  155.        
  156.     elif cmd == "get":
  157.         try:
  158.             xchat.command("say " + args[0] + " = " + xchat.get_pluginpref("nucbot:" + args[0]))
  159.         except:
  160.             xchat.command("say Error while reading " + args_str)
  161.            
  162.     elif cmd == "set":
  163.         try:
  164.             xchat.set_pluginpref("nucbot:" + args[0],args[1])
  165.             xchat.command("say " + args[0] + " set to " + args[1])
  166.         except:
  167.             xchat.command("say Error while writing in " + args[0])
  168.            
  169.     elif cmd == "tracepage":
  170.         try:
  171.             things = tracer.GetCity(args_str)
  172.             country = things["CountryName"]
  173.             region = things["RegionName"]
  174.             long = things["Longitude"]
  175.             lat = things["Latitude"]
  176.             if country == "":
  177.                 xchat.command("say No useful tracing possible.")
  178.             else:
  179.                 xchat.command("say Country: "+country+"    Region: "+region + "    Longitude: " + long + "    Latitude: " + lat)
  180.         except:
  181.             xchat.command("say No useful tracing possible.")
  182.        
  183.     elif cmd == "xsay":
  184.         try:
  185.             con=httplib.HTTPConnection("mniip.com/bot.lua?msg=" + args_str)
  186.             con.connect()
  187.         except Exception as e:
  188.             xchat.command("say Error while connecting to xsBot.")
  189.             print e
  190.        
  191. def fileget(word, word_eol, userdata):
  192.     trignick = word[0]
  193.     trigmsg = word[1]
  194.     if trigmsg.startswith("n:"):
  195.         try:
  196.             xchat.command("say " + word[1][2:len(word[1])] + " = " + xchat.get_pluginpref("nucbot:" + word[1][2:len(word[1])]))
  197.         except:
  198.             xchat.command("say Error while reading " + word[1][2:len(word[1])])
  199.    
  200. # hooks
  201. xchat.hook_print("Channel Msg Hilight", main)
  202. xchat.hook_print("Channel Message",fileget)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement