Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __module_name__ = "nucbot"
- __module_version__ = "1.0"
- __module_description__ = "An experimental bot script by nucular, made for HexChat 2.9.4"
- print __module_name__, __module_version__,"has been loaded\003"
- print __module_description__
- import xchat
- import io
- import fnmatch
- import random
- import subprocess
- import socket
- import httplib
- global s
- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- def check(host):
- try:
- s.connect((host,80))
- ret = host + " seems to be up from here."
- except:
- ret = host + " seems to be down from here."
- s.close()
- return ret
- api_key = "21246044e6856574301dfce647137e959737e8b4de9416a5141056aafae1a4a2"
- import pyipinfodb
- tracer = pyipinfodb.IPInfo(api_key)
- mynick = xchat.get_info('nick')
- # shortcut for pattern matching
- def match(one,two):
- return fnmatch.fnmatch(one,two)
- def gethost(nick):
- list = xchat.get_list("users")
- nicklist = []
- for i in list:
- nicklist = nicklist + [i.nick]
- return list[nicklist.index(nick)].host
- def getprefix(nick):
- list = xchat.get_list("users")
- nicklist = []
- for i in list:
- nicklist = nicklist + [i.nick]
- return list[nicklist.index(nick)].prefix
- # load admin list; set shortcuts
- # TODO: use host mask because safer
- global admins
- admins = xchat.get_pluginpref("nucbot-admins")
- if admins == None:
- xchat.set_pluginpref("nucbot-admins", list())
- admins = list()
- def isadmin(nick):
- return nick == "nucular_"
- def setadmin(nick):
- admins = admins + [nick]
- xchat.set_pluginpref("nucbot-admins", admins)
- def removeadmin(nick):
- if nick in admins:
- admins.remove(nick)
- xchat.set_pluginpref("nucbot-admins", admins)
- # create hook list for panic
- global hooks
- hooks = list()
- def eat(nick):
- xchat.command("me eats " + nick)
- def decide(ways):
- rndm = random.randrange(0,len(ways))
- return ways[rndm]
- def ignore(trignick,host):
- xchat.command("ignore "+host)
- xchat.command("me ignores "+trignick)
- def unignore(trignick,host):
- xchat.command("unignore "+host)
- xchat.command("me stops ignoring "+trignick)
- # Main things
- def main(word, word_eol, userdata):
- trignick = word[0]
- trigmsg = word[1]
- msg = trigmsg.split(" ")
- cmd = msg[1]
- args = msg[2:len(msg)]
- args_str = ""
- for i in args:
- args_str = args_str + i + " "
- args_str = args_str[0:len(args_str)-1]
- if cmd == "eat":
- if not args_str == "":
- eat(args_str)
- else:
- xchat.command("notice "+trignick+" Usage: eat <something>")
- elif cmd == "ignore":
- if isadmin(trignick):
- ignore(args_str,args_str)
- else:
- xchat.command("notice "+trignick+" You're not admin!")
- elif cmd == "unignore":
- if isadmin(trignick):
- unignore(args_str,args_str)
- else:
- xchat.command("notice "+trignick+" You're not admin!")
- elif cmd == "isadmin":
- if isadmin(args_str):
- xchat.command("say " + args_str + " is one of my admins.")
- else:
- xchat.command("say " + args_str + " is not my admin.")
- elif cmd == "decide":
- if not len(args)<2:
- xchat.command("say I would say... " + decide(args) + ".")
- elif len(args) == 0:
- xchat.command("notice " + trignick + " Usage: decide <way1> <way2> <...>")
- elif len(args) == 1:
- xchat.command("say I think, you can decide this by yourself.")
- elif cmd == "tracenick":
- try:
- things = tracer.GetCity(gethost(args_str).split("@")[1])
- country = things["CountryName"]
- region = things["RegionName"]
- long = things["Longitude"]
- lat = things["Latitude"]
- if country == "":
- xchat.command("say No useful tracing possible.")
- else:
- xchat.command("say Country: "+country+" Region: "+region + " Longitude: " + long + " Latitude: " + lat)
- except:
- xchat.command("say No useful tracing possible.")
- elif cmd =="gethost":
- xchat.command("say " + args_str + "'s host is " + gethost(args_str))
- elif cmd == "check":
- xchat.command("say "+ check(args_str))
- elif cmd == "get":
- try:
- xchat.command("say " + args[0] + " = " + xchat.get_pluginpref("nucbot:" + args[0]))
- except:
- xchat.command("say Error while reading " + args_str)
- elif cmd == "set":
- try:
- xchat.set_pluginpref("nucbot:" + args[0],args[1])
- xchat.command("say " + args[0] + " set to " + args[1])
- except:
- xchat.command("say Error while writing in " + args[0])
- elif cmd == "tracepage":
- try:
- things = tracer.GetCity(args_str)
- country = things["CountryName"]
- region = things["RegionName"]
- long = things["Longitude"]
- lat = things["Latitude"]
- if country == "":
- xchat.command("say No useful tracing possible.")
- else:
- xchat.command("say Country: "+country+" Region: "+region + " Longitude: " + long + " Latitude: " + lat)
- except:
- xchat.command("say No useful tracing possible.")
- elif cmd == "xsay":
- try:
- con=httplib.HTTPConnection("mniip.com/bot.lua?msg=" + args_str)
- con.connect()
- except Exception as e:
- xchat.command("say Error while connecting to xsBot.")
- print e
- def fileget(word, word_eol, userdata):
- trignick = word[0]
- trigmsg = word[1]
- if trigmsg.startswith("n:"):
- try:
- xchat.command("say " + word[1][2:len(word[1])] + " = " + xchat.get_pluginpref("nucbot:" + word[1][2:len(word[1])]))
- except:
- xchat.command("say Error while reading " + word[1][2:len(word[1])])
- # hooks
- xchat.hook_print("Channel Msg Hilight", main)
- xchat.hook_print("Channel Message",fileget)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement