#!/usr/bin/python
import socket, math, time, random, os, cleverbot, string, getpass
server = "irc.toribash.com"
port = 6667
nick = raw_input("nick: ")
chan = "#"+raw_input("channel: ").replace("#","")
banfile = open("ban","r")
ban = banfile.readline().split()
banfile.close()
logindatatb = {}
userdatatb = {}
for dir in os.listdir(".\\accounts"):
userdatatb[dir]={}
_tempfile_ = open("accounts\\"+dir+"\\data","r")
for l in _tempfile_:
if len(l)>0:
userdatatb[dir][l[:l.find(":")]]=l[l.find(":")+1:].strip()
_tempfile_.close()
_tempfile_ = None
logfile = open("log.txt","a")
logfile.write("\n\n"+time.asctime(time.localtime(time.time()))+"\n\n")
c_bold = "\x02"
c_neut = "\x0f"
c_color = "\x03"
c_under = "\x1f"
c_revs = "\x16"
c_ctcp = "\x01"
cbotsess = cleverbot.Session()
is_cbotsess = False
dsize = 6
qarr = []
is_trivia = False
line = ""
question = ""
answer = ""
currline = ""
hint = ""
is_checkreg = ""
reg_wait = False
is_checklog = ""
log_wait = False
oldtime = time.time()
triviachan = ""
triviafile = 0
exec_line = ""
do_exec = False
_umoney = False
_admcmdav = False
_modcmdav = False
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
irc.connect((server, port))
def send_raw(stri):
irc.send(stri+"\r\n")
print "-> "+stri+"\n"
logfile.write("-> "+stri+"\n")
def s(stri):
irc.send("PRIVMSG " + chan + " :" + str(stri) + "\r\n")
print "-> "+str(stri)+"\n"
logfile.write("-> "+str(stri)+"\n")
def sc(chnl, stri):
irc.send("PRIVMSG " + chnl + " :" + str(stri) + "\r\n")
print "-> "+str(stri)+"\n"
logfile.write("-> "+str(stri)+"\n")
def writedata(user,key,value):
try:
logindatatb[user.lower()][key]=value
_tempfile_ = open("accounts\\"+user.lower()+"\\data","w")
for ud in logindatatb[user.lower()]:
_tempfile_.write(ud+":"+logindatatb[user.lower()][ud]+"\n")
_tempfile_.close()
_tempfile_ = None
except Exception, le:
try:
userdatatb[user.lower()][key]=value
_tempfile_ = open("accounts\\"+user.lower()+"\\data","w")
for ud in userdatatb[user.lower()]:
_tempfile_.write(ud+":"+userdatatb[user.lower()][ud]+"\n")
_tempfile_.close()
_tempfile_ = None
except Exception, ue:
s("error: le: "+str(le)+"; ue: "+str(ue))
def deletedata(user,key):
try:
del logindatatb[user.lower()][key]
_tempfile_ = open("accounts\\"+user.lower()+"\\data","w")
for ud in logindatatb[user.lower()]:
_tempfile_.write(ud+":"+logindatatb[user.lower()][ud]+"\n")
_tempfile_.close()
_tempfile_ = None
except Exception, le:
try:
del userdatatb[user.lower()][key]
_tempfile_ = open("accounts\\"+user.lower()+"\\data","w")
for ud in userdatatb[user.lower()]:
_tempfile_.write(ud+":"+userdatatb[user.lower()][ud]+"\n")
_tempfile_.close()
_tempfile_ = None
except Exception, ue:
s("error: le: "+str(le)+"; ue: "+str(ue))
irc.send("NICK " + nick + "\r\n")
irc.send("USER " + nick + " * * :nigger exterminator\r\n")
irc.send("PRIVMSG nickserv :identify " + getpass.getpass("nickserv password (no echo): ") + "\r\n")
time.sleep(0.5)
send_raw("JOIN " + chan)
while True:
data = irc.recv(4096)
for d in data.split("\r\n")[:-1]:
print d+"\n"
logfile.write(d+"\n")
full_user = d[1:d.find(" ")]
u = d[1:d.find("!")]
hostname = d[d.find("@")+1:d.find(" ")]
irccmd = d[d.find(" ")+1:][:d[d.find(" ")+1:].find(" ")]
m = d[d[1:].find(":")+2:]
if do_exec and len(exec_line)>0:
try:
exec(exec_line)
except Exception, e:
s("error: "+str(e))
do_exec = False
if is_checkreg=="" and is_checklog=="":
chan = d[d.find("PRIVMSG ")+8:]
chan = chan[:chan.find(" ")]
if chan==nick:
chan=u
if d[:6]=="PING :":
send_raw("PONG :"+d[6:].rstrip())
elif not is_checkreg=="" and full_user==server:
if d==":"+server+" 307 "+nick+" "+is_checkreg+" :is a registered nick":
if not os.path.exists("accounts\\"+is_checkreg.lower()):
userdatatb[is_checkreg.lower()]={'admin': 'false', 'mod': 'false'}
os.makedirs("accounts\\"+is_checkreg.lower())
_tempfile_ = open("accounts\\"+is_checkreg.lower()+"\\data","w")
_tempfile_.write("admin:false\nmod:false\n")
_tempfile_.close()
_tempfile_ = None
s("user '"+is_checkreg.lower()+"' successfully registered.")
else:
s("user '"+is_checkreg.lower()+"' is already registered.")
is_checkreg = ""
reg_wait = False
if not is_checkreg=="":
if reg_wait:
reg_wait = False
else:
s("user '"+is_checkreg.lower()+"' is not registered (or identified) in "+server)
is_checkreg = ""
elif not is_checklog=="" and full_user==server:
if d==":"+server+" 307 "+nick+" "+is_checklog+" :is a registered nick":
try:
try:
del userdatatb[is_checklog.lower()]
except:
pass
logindatatb[is_checklog.lower()]={}
_tempfile_ = open("accounts\\"+is_checklog.lower()+"\\data","r")
for l in _tempfile_:
if len(l)>0:
logindatatb[is_checklog.lower()][l[:l.find(":")]]=l[l.find(":")+1:].strip()
_tempfile_.close()
_tempfile_ = None
s("successfully loaded '"+is_checklog.lower()+"''s info.")
except Exception, e:
s("user '"+is_checklog.lower()+"' isn't registered.")
is_checklog = ""
log_wait = False
if not is_checklog=="":
if log_wait:
log_wait = False
else:
s("user '"+is_checklog.lower()+"' is not registered (or identified) in "+server)
is_checklog = ""
elif irccmd == "QUIT" or irccmd == "NICK" or irccmd == "JOIN":
try:
if logindatatb[u.lower()]:
userdatatb[u.lower()] = logindatatb[u.lower()]
del logindatatb[u.lower()]
if irccmd == "NICK":
if logindatatb[d[d[1:].find(":")+2]]:
userdatatb[d[d[1:].find(":")+2]] = logindatatb[d[d[1:].find(":")+2]]
del logindatatb[d[d[1:].find(":")+2]]
except:
pass
elif d[:1]==":" and not u.lower() in ban and not hostname.lower() in ban and irccmd == "PRIVMSG":
try:
if logindatatb[u.lower()]['admin']=="true":
_admcmdav = True
except:
pass
try:
if logindatatb[u.lower()]['mod']=="true":
_modcmdav = True
except:
pass
if m[:5]==".help":
s("avaliable commands and params (precede commands with '.'):")
s("help, say (str), nick (newnick), eval (equation/code), exec (code), admadd (newadmin), admrem (admin), admlist, join (chan), leave (chan), saychan (channel/user:msg), identify (nickservpw), updatestatus, ban (user/hostname), unban (user/hostname), banlist, time, dice (size; default is 6), google (search), youtube (search), trivia (file no.), stoptrivia, skip, money, mode (+- users), register, login, logout, cbon, cboff, roul, data [opt: user], doubleit")
s("modadd (newmod), modrem (mod), modlist, send (user:amount), restart, owner +/- [opt: user], sop +/- [opt: user], op +/- [opt: user], hop +/- [opt: user], voice +/- [opt: user]")
s("other interpreted stuff: o/; don't you agree, y-bot?; dance, y-bot; y-bot: sentence (parsed by cleverbot [if query, any non-cmd is parsed])")
s("feel free to query the bot, it interprets all messages.")
elif m[:5]==".say ":
s(m[5:])
elif m[:6]==".nick ":
if _admcmdav or _modcmdav:
send_raw("NICK :"+m[6:])
nick = m[6:]
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:6]==".eval ":
if _admcmdav:
if u.lower()!="yoyo":
if m[6:].lower().find("getpass.")<0 and m[6:].lower().find("input")<0 and m[6:].lower().find("import")<0 and m[6:].lower().find("os.")<0 and m[6:].lower().find("exit()")<0 and m[6:].lower().find("sys.")<0 and m[6:].lower().find("webbrowser.")<0 and m[6:].lower().find("exec_line")<0 and m[6:].lower().find("do_exec")<0 and m[6:].lower().find("writedata")<0 and m[6:].lower().find("deletedata")<0 and m[6:].lower().find("send_raw")<0 and m[6:].lower().find("irc.")<0 and m[6:].lower().find("exec")<0 and m[6:].lower().find("eval")<0 and m[6:].lower().find("open")<0 and m[6:].lower().find("time.")<0 and m[6:].lower().find("login")<0 and m[6:].lower().find("user")<0:
try:
s(eval(m[6:]))
except Exception, e:
s("error: "+str(e))
s("evaluated: "+m[6:])
else:
s("action prohibited; user '"+u.lower()+"' banned.")
writedata(u.lower(),'admin','false')
ban = ban + [u.lower()]
banfile=open("ban","w")
banfile.write(" ".join(ban))
banfile.close()
else:
try:
s(eval(m[6:]))
except Exception, e:
s("error: "+str(e))
s("evaluated: "+m[6:])
else:
if m[6:].translate(None, string.letters)==m[6:]:
try:
s(eval(m[6:]))
except Exception, e:
s("error: "+str(e))
else:
s("non-admins can only use numbers and operators in eval.")
elif m[:6]==".exec ":
if _admcmdav:
if u.lower()!="yoyo":
if m[6:].lower().find("getpass.")<0 and m[6:].lower().find("input")<0 and m[6:].lower().find("import")<0 and m[6:].lower().find("os.")<0 and m[6:].lower().find("exit()")<0 and m[6:].lower().find("sys.")<0 and m[6:].lower().find("webbrowser.")<0 and m[6:].lower().find("exec_line")<0 and m[6:].lower().find("do_exec")<0 and m[6:].lower().find("writedata")<0 and m[6:].lower().find("deletedata")<0 and m[6:].lower().find("send_raw")<0 and m[6:].lower().find("irc.")<0 and m[6:].lower().find("exec")<0 and m[6:].lower().find("eval")<0 and m[6:].lower().find("open")<0 and m[6:].lower().find("time.")<0 and m[6:].lower().find("login")<0 and m[6:].lower().find("user")<0:
try:
exec(m[6:])
except Exception, e:
s("error: "+str(e))
s("executed: "+m[6:])
else:
s("action prohibited; user '"+u.lower()+"' banned.")
writedata(u.lower(),'admin','false')
ban = ban + [u.lower()]
banfile=open("ban","w")
banfile.write(" ".join(ban))
banfile.close()
else:
try:
exec(m[6:])
except Exception, e:
s("error: "+str(e))
s("executed: "+m[6:])
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:8]==".admadd ":
if _admcmdav:
if not m[8:].lower() in ban:
try:
if not logindatatb[m[8:].lower()]['admin']=="true":
writedata(m[8:].lower(),'admin','true')
s("added '"+m[8:].lower()+"' to adminlist.")
else:
s("user '"+m[8:].lower()+"' is already an admin.")
except:
try:
if not userdatatb[m[8:].lower()]['admin']=="true":
writedata(m[8:].lower(),'admin','true')
s("added '"+m[8:].lower()+"' to adminlist.")
else:
s("user '"+m[8:].lower()+"' is already an admin.")
except:
s("user '"+m[8:].lower()+"' is not registered (or logged in).")
else:
s("user '"+m[8:].lower()+"' is banned.")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:8]==".admrem ":
if _admcmdav:
if m[8:].lower() != "yoyo":
try:
if logindatatb[m[8:].lower()]['admin']=="true":
writedata(m[8:].lower(),'admin','false')
s("removed '"+m[8:].lower()+"' from adminlist.")
else:
s("user '"+m[8:].lower()+"' is not an admin.")
except:
try:
if userdatatb[m[8:].lower()]['admin']=="true":
writedata(m[8:].lower(),'admin','false')
s("removed '"+m[8:].lower()+"' from adminlist.")
else:
s("user '"+m[8:].lower()+"' is not an admin.")
except:
s("user '"+m[8:].lower()+"' is not registered (or logged in).")
else:
s("how dare you try to remove the almighty Yoyo, "+u+"?")
s("action prohibited; user '"+u.lower()+"' banned.")
writedata(u.lower(),'admin','false')
ban = ban + [u.lower()]
banfile=open("ban","w")
banfile.write(" ".join(ban))
banfile.close()
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:8]==".admlist":
_tempstring = "current admins (bold: online admins): "
for ud in logindatatb:
try:
if logindatatb[ud]['admin']=="true":
_tempstring = _tempstring + c_bold
try:
_tempstring = _tempstring + logindatatb[ud]['adm_cstm']
if logindatatb[ud]['adm_cstm'].translate(None,string.letters)!=logindatatb[ud]['adm_cstm']:
_tempstring = _tempstring + " "
except:
pass
_tempstring = _tempstring + ud + c_neut + ", "
except:
pass
for ud in userdatatb:
try:
if userdatatb[ud]['admin']=="true":
_tempstring = _tempstring + ud + ", "
except:
pass
s(_tempstring[:-2])
_tempstring = None
elif m[:8]==".modadd ":
if _admcmdav:
if not m[8:].lower() in ban:
try:
if not logindatatb[m[8:].lower()]['mod']=="true":
writedata(m[8:].lower(),'mod','true')
s("added '"+m[8:].lower()+"' to modlist.")
else:
s("user '"+m[8:].lower()+"' is already a mod.")
except:
try:
if not userdatatb[m[8:].lower()]['mod']=="true":
writedata(m[8:].lower(),'mod','true')
s("added '"+m[8:].lower()+"' to modlist.")
else:
s("user '"+m[8:].lower()+"' is already a mod.")
except:
s("user '"+m[8:].lower()+"' is not registered (or logged in).")
else:
s("user '"+m[8:].lower()+"' is banned.")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:8]==".modrem ":
if _admcmdav:
try:
if logindatatb[m[8:].lower()]['mod']=="true":
writedata(m[8:].lower(),'mod','false')
s("removed '"+m[8:].lower()+"' from modlist.")
else:
s("user '"+m[8:].lower()+"' is not a mod.")
except:
try:
if userdatatb[m[8:].lower()]['mod']=="true":
writedata(m[8:].lower(),'mod','false')
s("removed '"+m[8:].lower()+"' from modlist.")
else:
s("user '"+m[8:].lower()+"' is not a mod.")
except:
s("user '"+m[8:].lower()+"' is not registered (or logged in).")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:8]==".modlist":
_tempstring = "current mods (bold: online mods): "
for ud in logindatatb:
try:
if logindatatb[ud]['mod']=="true":
_tempstring = _tempstring + c_bold + ud + c_bold + ", "
except:
pass
for ud in userdatatb:
try:
if userdatatb[ud]['mod']=="true":
_tempstring = _tempstring + ud + ", "
except:
pass
s(_tempstring[:-2])
_tempstring = None
elif m[:2]=="o/":
s("\o")
s("o/*\o")
elif m[:6]==".join ":
if _admcmdav or _modcmdav:
if m[6:14].lower() != "#support" and m[6:15].lower() != "#toribash":
send_raw("JOIN :"+m[6:])
s("joined channel '"+m[6:]+"'.")
else:
s("prohibited channel.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:7]==".leave ":
if _admcmdav or _modcmdav:
if m[7:7+len(chan)]!=chan:
send_raw("PART :"+m[7:])
s("left channel '"+m[7:]+"'.")
else:
s("not allowed.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:9]==".saychan ":
if _admcmdav or _modcmdav:
sc(m[9:m.find(":")],m[m.find(":")+1:])
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:10]==".identify ":
if _admcmdav:
irc.send("PRIVMSG NickServ :identify "+m[10:]+"\r\n")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:13]==".updatestatus":
if _admcmdav:
send_raw("PRIVMSG NickServ :update")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:5]==".ban ":
if _admcmdav or _modcmdav:
if m[5:].lower() != "yoyo":
try:
if logindatatb[m[5:].lower()]['admin']=='false' and logindatatb[m[5:].lower()]['mod']=='false':
_tempdoban_ = True
else:
_tempdoban_ = False
except:
_tempdoban_ = True
if _tempdoban_:
if not m[5:].lower() in ban:
ban = ban + [m[5:].lower()]
banfile=open("ban","w")
banfile.write(" ".join(ban))
banfile.close()
s("user '"+m[5:].lower()+"' is now banned.")
else:
s("user '"+m[5:].lower()+"' is already banned.")
else:
s("user '"+m[5:].lower()+"' is an admin/mod.")
_tempdoban_ = None
else:
s("how dare you try to ban the almighty Yoyo, "+u+"?")
s("action prohibited; user '"+u.lower()+"' banned.")
writedata(u.lower(),'admin','false')
ban = ban + [u.lower()]
banfile=open("ban","w")
banfile.write(" ".join(ban))
banfile.close()
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:7]==".unban ":
if _admcmdav or _modcmdav:
if m[7:].lower() in ban:
del ban[ban.index(m[7:].lower())]
banfile=open("ban","w")
banfile.write(" ".join(ban))
banfile.close()
s("user '"+m[7:].lower()+"' is now unbanned.")
else:
s("user '"+m[7:].lower()+"' is not banned.")
else:
("user '"+u+"' doesn't have admin/mod permissions.")
elif m[:8]==".banlist":
s("current banlist: "+", ".join(ban))
elif m.lower()=="don't you agree, "+nick.lower()+"?":
if _admcmdav:
if m=="DON'T YOU AGREE, "+nick.upper()+"?":
s(c_bold+"I ABSOLUTELY AGREE WITH YOU, "+u.upper()+"."+c_bold)
else:
s("I absolutely agree with you, "+u.lower()+".")
elif _modcmdav:
s("you might be right, "+u.lower()+".")
else:
s("sorry, but I have to disagree, "+u.lower()+".")
elif m.lower()=="dance, "+nick.lower():
if m=="DANCE, "+nick.upper():
s(c_ctcp + "ACTION "+ c_bold + "DANCES EVEN WILDER" + c_ctcp)
else:
s(c_ctcp + "ACTION dances wildly" + c_ctcp)
elif m[:5]==".time":
s("current time: "+time.asctime(time.localtime(time.time())))
elif m[:5]==".dice":
dsize = 6
if len(m[6:]) != 0:
try:
if int(float(m[6:]))>0:
dsize = int(float(m[6:]))
except Exception, e:
s("invalid number, using default (error: "+str(e)+")")
s("roll: "+str(random.randint(1,dsize)))
elif m[:8]==".google ":
s("http://google.com/search?q="+m[8:].replace(" ","+"))
elif m[:9]==".youtube ":
s("http://www.youtube.com/results?search_query="+m[9:].replace(" ","+"))
elif m[:7]==".trivia":
if _admcmdav or _modcmdav:
if not is_trivia:
is_trivia = True
triviachan = chan
triviafile = random.randint(1,191)
qfile = open("lst\\"+"%03d"%(triviafile,)+".txt","r")
if len(m[8:]) != 0:
try:
triviafile = int(float(m[8:]))
qfile = open("lst\\"+"%03d"%(triviafile,)+".txt","r")
except Exception, e:
sc(triviachan, "invalid file, using random (error: "+str(e)+")")
qarr = []
while True:
line = qfile.readline()
if len(line)>0:
qarr = qarr + [line]
else:
break
currline = qarr[random.randint(0,len(qarr)-1)]
question = currline[:currline.find("*")]
answer = currline[currline.find("*")+1:]
if answer.find("*"):
answer = answer[answer.find("*")+1:]
sc(triviachan, "trivia started, using file %d."%(triviafile,))
if len(answer)>3:
hint = answer[0]
for i in range(1,len(answer)-2):
if answer[i]==" ":
hint = hint + " "
else:
hint = hint + "-"
hint = (hint + answer[-2])
else:
hint = "-"*len(answer)
sc(triviachan, question+" - hint: "+hint)
oldtime = time.time()
else:
s("trivia is already running.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:11]==".stoptrivia":
if _admcmdav or _modcmdav:
if is_trivia:
is_trivia = False
s("trivia stopped.")
triviafile = 0
else:
s("trivia is not running.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:11]==".skip":
if _admcmdav or _modcmdav:
if is_trivia:
sc(triviachan, "question skipped; answer is: "+answer)
currline = qarr[random.randint(0,len(qarr)-1)]
question = currline[:currline.find("*")]
answer = currline[currline.find("*")+1:]
if answer.find("*"):
answer = answer[answer.find("*")+1:]
if len(answer)>3:
hint = answer[0]
for i in range(1,len(answer)-2):
if answer[i]==" ":
hint = hint + " "
else:
hint = hint + "-"
hint = (hint + answer[-2])
else:
hint = "-"*len(answer)
sc(triviachan, question+" - hint: "+hint)
oldtime = time.time()
else:
s("trivia is not running.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:6]==".money":
s("money:")
for d in logindatatb:
try:
s(d+": "+logindatatb[d]['money'])
except:
pass
for d in userdatatb:
try:
s(d+": "+userdatatb[d]['money'])
except:
pass
elif m[:6]==".mode ":
if _admcmdav:
send_raw("MODE "+chan+" "+m[6:])
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:9]==".register":
if is_checkreg=="":
is_checkreg = u
reg_wait = True
send_raw("WHOIS "+u)
s("attempting to register user '"+u.lower()+"'.")
else:
s("someone is already registering, please wait.")
elif m[:6]==".login":
if is_checklog=="":
try:
_tempcheck_ = logindatatb[u.lower()]
except:
_tempcheck_ = None
if _tempcheck_ == None:
is_checklog = u
log_wait = True
send_raw("WHOIS "+u)
s("logging user '"+u.lower()+"' in.")
else:
s("user '"+u.lower()+"' already logged in.")
_tempcheck_ = None
else:
s("someone is already logging in, please wait.")
elif m[:7]==".logout":
try:
userdatatb[u.lower()] = logindatatb[u.lower()]
del logindatatb[u.lower()]
s("user '"+u.lower()+"' logged out.")
except:
s("user '"+u.lower()+"' isn't logged in.")
elif m[:5]==".cbon":
if _admcmdav or _modcmdav:
if not is_cbotsess:
is_cbotsess = True
s("cleverbot is now on.")
else:
s("cleverbot is already running.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:6]==".cboff":
if _admcmdav or _modcmdav:
if is_cbotsess:
is_cbotsess = False
s("cleverbot is now off.")
else:
s("cleverbot is not running.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:5]==".roul":
if random.randint(1,6)==3:
send_raw('kick %s %s :boom'%(chan,u))
elif m[:5]==".data":
if len(m[6:])>0:
if _admcmdav or _modcmdav:
s("data saved for user '"+m[6:].lower()+"':")
try:
for dkey, dval in logindatatb[m[6:].lower()].iteritems():
s(dkey+": "+dval)
except Exception, le:
try:
for dkey, dval in userdatatb[m[6:].lower()].iteritems():
s(dkey+": "+dval)
except Exception, ue:
s("error: user not found in either data table (le: "+str(le)+"; ue: "+str(ue)+").")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
else:
s("data saved for user '"+u.lower()+"':")
try:
for dkey, dval in logindatatb[u.lower()].iteritems():
s(dkey+": "+dval)
except Exception, e:
s("error: user data not found in the login data table (e: "+str(e)+").")
elif m[:9]==".doubleit":
try:
if logindatatb[u.lower()]['money']:
if random.randint(1,3)==1:
writedata(u.lower(),'money',str(int(logindatatb[u.lower()]['money'])*2))
s("money doubled.")
else:
writedata(u.lower(),'money',str(int(math.ceil(float(logindatatb[u.lower()]['money'])/2))))
s("money halved.")
except Exception, e:
if str(e)=="'"+u.lower()+"'":
s("user '"+u.lower()+"' not registered/logged in.")
elif str(e)=="'money'":
s("user '"+u.lower()+"' doesn't have money.")
else:
s("error: "+str(e))
elif m[:6]==".send ":
if m.find(":")>0:
try:
if logindatatb[u.lower()]['money'] and logindatatb[m[6:m.find(":")].lower()]:
_umoney = True
except:
pass
if _umoney:
if m[m.find(":")+1:].translate(None,string.letters)==m[m.find(":")+1:]:
if m[m.find(":")+1:].translate(None,"-")==m[m.find(":")+1:] and int(m[m.find(":")+1:].translate(None,"-"))<=int(logindatatb[u.lower()]['money']):
writedata(u.lower(),'money',str(int(logindatatb[u.lower()]['money'])-int(m[m.find(":")+1:])))
try:
writedata(m[6:m.find(":")].lower().lower(),'money',str(int(logindatatb[m[6:m.find(":")].lower().lower()]['money'])+int(m[m.find(":")+1:])))
except:
try:
writedata(m[6:m.find(":")].lower().lower(),'money',m[m.find(":")+1:])
except:
pass
s("sent %s money from %s to %s."%(m[m.find(":")+1:],u.lower(),m[6:m.find(":")].lower()))
else:
s("transfer amount can't be negative or above your total money.")
else:
s("invalid number.")
else:
s("error transfering money. check if both users are registered/logged in.")
_umoney = False
else:
s("incorrectly formatted command.")
elif m[:8]==".restart":
if _admcmdav and u.lower()=="yoyo":
send_raw("QUIT :-")
os.system("y-bot.bat")
exit()
else:
s("owner restricted command.")
elif m[:6]==".owner":
if _admcmdav:
if len(m[7:])>0:
if m[7]=="+" or m[7]=="-":
if len(m[9:])>0:
send_raw("MODE %s %sq %s"%(chan,m[7],m[9:]))
else:
send_raw("MODE %s %sq %s"%(chan,m[7],u))
else:
s("incorrect formatting.")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:4]==".sop":
if _admcmdav:
if len(m[5:])>0:
if m[5]=="+" or m[5]=="-":
if len(m[7:])>0:
send_raw("MODE %s %sa %s"%(chan,m[5],m[7:]))
else:
send_raw("MODE %s %sa %s"%(chan,m[5],u))
else:
s("incorrect formatting.")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:3]==".op":
if _admcmdav:
if len(m[4:])>0:
if m[4]=="+" or m[4]=="-":
if len(m[6:])>0:
send_raw("MODE %s %so %s"%(chan,m[4],m[6:]))
else:
send_raw("MODE %s %so %s"%(chan,m[4],u))
else:
s("incorrect formatting.")
else:
s("user '"+u.lower()+"' doesn't have admin permissions.")
elif m[:4]==".hop":
if _admcmdav or _modcmdav:
if len(m[5:])>0:
if m[5]=="+" or m[5]=="-":
if len(m[7:])>0:
send_raw("MODE %s %sh %s"%(chan,m[5],m[7:]))
else:
send_raw("MODE %s %sh %s"%(chan,m[5],u))
else:
s("incorrect formatting.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
elif m[:6]==".voice":
if _admcmdav or _modcmdav:
if len(m[7:])>0:
if m[7]=="+" or m[7]=="-":
if len(m[9:])>0:
send_raw("MODE %s %sv %s"%(chan,m[7],m[9:]))
else:
send_raw("MODE %s %sv %s"%(chan,m[7],u))
else:
s("incorrect formatting.")
else:
s("user '"+u.lower()+"' doesn't have admin/mod permissions.")
if is_cbotsess:
if m[:len(nick)+2].lower()==nick.lower()+": ":
s(cbotsess.Ask(m[len(nick)+2:]).lower().replace("cleverbot",nick.lower()))
elif chan==u and m[0]!=".":
try:
s(cbotsess.Ask(m).lower().replace("cleverbot",nick.lower()))
except:
pass
if is_trivia:
if oldtime+30<=time.time():
sc(triviachan, "timelimit reached; answer is: "+answer)
currline = qarr[random.randint(0,len(qarr)-1)]
question = currline[:currline.find("*")]
answer = currline[currline.find("*")+1:]
if answer.find("*"):
answer = answer[answer.find("*")+1:]
if len(answer)>3:
hint = answer[0]
for i in range(1,len(answer)-2):
if answer[i]==" ":
hint = hint + " "
else:
hint = hint + "-"
hint = (hint + answer[-2])
else:
hint = "-"*len(answer)
sc(triviachan, question+" - hint: "+hint)
oldtime = time.time()
if m.lower().strip().find(answer.lower().strip()) > -1:
sc(triviachan, u+" wins; answer is: "+answer)
try:
if logindatatb[u.lower()]:
logindatatb[u.lower()]['money'] = str(int(logindatatb[u.lower()]['money'])+10)
writedata(u.lower(),'money',logindatatb[u.lower()]['money'])
except:
try:
if logindatatb[u.lower()]:
logindatatb[u.lower()]['money'] = "10"
writedata(u.lower(),'money',logindatatb[u.lower()]['money'])
except:
pass
currline = qarr[random.randint(0,len(qarr)-1)]
question = currline[:currline.find("*")]
answer = currline[currline.find("*")+1:]
if answer.find("*"):
answer = answer[answer.find("*")+1:]
if len(answer)>3:
hint = answer[0]
for i in range(1,len(answer)-2):
if answer[i]==" ":
hint = hint + " "
else:
hint = hint + "-"
hint = (hint + answer[-2])
else:
hint = "-"*len(answer)
sc(triviachan, question+" - hint: "+hint)
oldtime = time.time()
_admcmdav = False
_modcmdav = False