Skip to content

Instantly share code, notes, and snippets.

@mzhang28
Created March 1, 2015 19:03
Show Gist options
  • Save mzhang28/265f9c6186a00115711a to your computer and use it in GitHub Desktop.
Save mzhang28/265f9c6186a00115711a to your computer and use it in GitHub Desktop.
import sys;
import socket;
import string;
import random;
import urllib2;
import hashlib;
def genprefix():
return (random.choice("abcdef") + hashlib.md5(random.choice([
"heibot", "asdfbot",
"haibot", "no_bot",
"highbot", "yes_bot",
"haiibot", "shitbot",
"lowbot", "greatbot",
"hei_bot", "bestbot",
"hai_bot", "rekbot",
"ayybot", "godbot",
"yo_bot", "banbot",
"not_a_bot", "hahabot",
]).replace("bot", random.choice(["bawt", "b0t", "ba0t", "boat", "bott"]))).hexdigest()[:12].strip());
HOST = "irc.mibbit.net";
PORT = 6667;
NICK = genprefix().strip();
CHANNEL = "#sctf_ochat";
def mix(s, c=' ', n=1):
return ''.join(s[i:i+n]+c for i in range(0,len(s),n));
## words = [i for i in open("wordlist.txt").read().split("\n") if len(i)>4];
url = "https://raw.githubusercontent.com/heibot/heibot/3cd44ba1d6af011a11f5cfb8b8b73be3d14d0dae/wordlist.txt";
response = urllib2.urlopen(url);
words = [i for i in response.read().split("\n") if len(i) > 4];
outcomes = ["It is certain", "It is decidedly so", "Without a doubt", "Yes definitely", "You may rely on it", "As I see it, yes", "Most likely", "Outlook good", "Yes", "Signs point to yes", "Reply hazy try again", "Ask again later", "Better not tell you now", "Cannot predict now", "Concentrate and ask again ", "Don't count on it", "My reply is no", "My sources say no", "Outlook not so good", "Very doubtful", "no.", "START", "A", "B", "UP", "DOWN", "LEFT", "RIGHT", "SELECT"];
slots = 6;
s = socket.socket();
s.connect((HOST, PORT));
s.send("NICK "+NICK+"\n");
s.send("USER "+NICK+" "+NICK+" "+NICK+" :"+NICK+"\n");
heicounter = 0;
connected = False;
stop = False;
greet = False;
irc = {
"chan": CHANNEL,
}
# f = open("log.txt", "a");
bitches = set();
commands = ["help", "helixfossil (or hf)", "md5", "roll", "flag", "rek", "<3", "tell"];
# version 2.1 - added tell and fixed help
# version 2.2 - fixed tell and greeting
# version 2.3 - fixed tell with colons
motd = [
"Hei! I'm a bot. Type `help to see what I can do!",
"Latest update: screw colons i'm done with that"
];
def generate_flag():
flag = "";
for i in range(4):
if i != 0:
flag += "_";
flag += random.choice(words);
return flag;
def parse(line):
global NICK, PORT, CHANNEL, HOST, s, connected, prefix;
if False: #line.find("heibot leave") != -1:
# f.close();
s.send("QUIT\n");
s.send("NICK "+NICK+"\n");
s.send("USER "+NICK+" "+NICK+" "+NICK+" :"+NICK+"\n");
else:
if line.lower().find(("KICK #sCTF_ochat " + NICK).lower()) != -1 or\
line.lower().find((NICK + " #sCTF_ochat :You are banned").lower()) != -1:
print "\nSHIT GOT KICKED\n";
s.close();
connected = False;
NICK = genprefix();
s = socket.socket();
s.connect((HOST, PORT));
s.send("NICK "+NICK+"\n");
s.send("USER "+NICK+" "+NICK+" "+NICK+" :"+NICK+"\n");
if line.lower().find(("JOIN :" + CHANNEL).lower()) != -1:
username = line.split(":")[1].split("!")[0];
# s.send("PRIVMSG %s :welcome, %s\n" % (irc['chan'], username));
if False:# username.lower().find("bot") != -1:
string = "KICK %s %s :heibot is the only real bot\n" % (irc['chan'], username);
# print string;
s.send(string);
elif username.lower().find(NICK.lower()) != -1:
pass;
elif username.lower().find("axod") != -1:
pass;
else:
username = line.split(":")[1].split("!")[0];
s.send("PRIVMSG %s :hei, %s\n" % (irc['chan'], username));
if len(line.split(":")) == 3:
username = line.split(":")[1].split("!")[0];
message = ":".join(line.split(":")[2:]);
if message.split(" ")[0].strip().strip(",").strip(":").lower() in ["hi", "hei", "hello"]:
random.seed();
k = random.randint(1, 1000);
if k < 900:
s.send("PRIVMSG %s :hei, %s\n" % (irc['chan'], username));
else:
s.send("PRIVMSG %s :fuck you, %s, i hope you die a horribly gruesome death\n" % (irc['chan'], username));
if message.split(" ")[0].strip().strip(",").strip(":").lower() in ["lol"] or message.lower().find("lol") != -1:
s.send("PRIVMSG %s :%s, but did you actually laugh out loud?\n" % (irc['chan'], username));
if message.find("`") != -1:
actual = message[1:].split(" ");
command = actual[0];
if command.find("roll") != -1:
highest = 1000;
try:
if len(actual) == 2:
highest = int(actual[1]);
if highest < 1:
raise Exception()
s.send("PRIVMSG %s :%s rolled %d\n" % (irc['chan'], username, random.randint(1, highest)));
except Exception:
a = 0;
s.send("PRIVMSG %s :fuck you %s\n" % (irc['chan'], username));
elif command.find("help") != -1:
s.send("PRIVMSG %s :%s\n" % (irc['chan'], "To use the commands, type ` (that's the thing next to 1 on your keyboard) and then the command name, like `help."));
s.send("PRIVMSG %s :Some commands are: %s.\n" % (irc['chan'], ", ".join(sorted(commands)))); # , "https://github.com/failedxyz/heibot/blob/master/README.md"));
elif command.find("tell") != -1:
q = message.strip("\r\n")[5:].split(" ");
# print q;
user = q[1];
# print user;
try:
if len(user) < 1:
raise Exception();
if user.lower() == NICK.lower():
s.send("PRIVMSG %s :got it\n" % irc['chan']);
elif user.lower() == username.lower():
s.send("PRIVMSG %s :lol u talk to urself u weirdo\n" % irc['chan']);
else:
s.send("PRIVMSG %s :%s, %s says: '%s'\n" % (irc['chan'], user, username, " ".join(q[2:])));
except Exception:
s.send("PRIVMSG %s :Usage: `tell [username] [message]\n" % (irc['chan']));
elif command.find("flag") != -1:
try:
problem = message.strip("\r\n")[6:];
# print problem;
if len(problem) < 1:
raise Exception();
string = "PRIVMSG %s :%s, sending the flag for %s to you in private message!\n" % (irc['chan'], username, problem);
# print string;
s.send(string);
s.send("PRIVMSG %s :%s\n" % (username, generate_flag()));
except Exception:
s.send("PRIVMSG %s :Usage: `flag [problem_name]\n" % (irc['chan']));
elif command.find("rek") != -1:
user = message.strip("\r\n")[5:];
print user;
try:
if len(user) < 1:
raise Exception();
s.send("PRIVMSG %s :%s, you just got rekt by %s\n" % (irc['chan'], user, username));
except Exception:
s.send("PRIVMSG %s :Usage: `rek [username]\n" % (irc['chan']));
elif command.find("md5") != -1:
try:
stuff = message.strip("\r\n")[5:];
# print stuff;
if len(stuff) < 1:
raise Exception();
s.send("PRIVMSG %s :md5 of \"%s\" is %s\n" % (irc['chan'], stuff, __import__("hashlib").md5(stuff).hexdigest()));
except Exception:
s.send("PRIVMSG %s :Usage: `md5 [stuff]\n" % (irc['chan']));
elif command.find("helixfossil") != -1 or command.find("hf") != -1:
s.send("PRIVMSG %s :%s, %s\n" % (irc['chan'], username, random.choice(outcomes)));
elif command.find("<3") != -1:
bitches.add(username);
s.send("PRIVMSG %s :<3 %s\n" % (irc['chan'], username));
elif command.find("bitches") != -1:
s.send("PRIVMSG %s :My bitches are: %s\n" % (irc['chan'], ", ".join(list(bitches))));
while not stop:
line = s.recv(1024);
print line.strip();
f = open("log.txt", "a");
f.write("%s\n" % line.strip());
f.close();
if line.find("PRIVMSG %s" % irc['chan']) != 1:
parse(line);
if line.find("PING") != -1:
s.send("PONG :" + line.split(":")[1]);
if not connected:
s.send("JOIN %(chan)s\n" % irc);
if not greet:
greet = True;
for message in motd:
s.send("PRIVMSG %s :%s\n" % (irc['chan'], message));
if stop:
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment