idk what all I did really.
This commit is contained in:
parent
616e149d57
commit
895721d05e
2 changed files with 197 additions and 167 deletions
2
core.py
2
core.py
|
@ -21,12 +21,14 @@ def is_dead(thr):
|
||||||
thr.join(timeout=0)
|
thr.join(timeout=0)
|
||||||
return not thr.is_alive()
|
return not thr.is_alive()
|
||||||
|
|
||||||
|
|
||||||
def start(server):
|
def start(server):
|
||||||
t = Thread(target=launch, args=(server,))
|
t = Thread(target=launch, args=(server,))
|
||||||
t.daemon = True
|
t.daemon = True
|
||||||
t.start()
|
t.start()
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("[LOG][CORE] Begin initialization")
|
print("[LOG][CORE] Begin initialization")
|
||||||
for server in servers:
|
for server in servers:
|
||||||
|
|
66
ircbot.py
66
ircbot.py
|
@ -57,8 +57,9 @@ e = encoding
|
||||||
adminnames = servers[server]["admins"]
|
adminnames = servers[server]["admins"]
|
||||||
exitcode = f"bye {botnick.lower()}"
|
exitcode = f"bye {botnick.lower()}"
|
||||||
ircmsg = ""
|
ircmsg = ""
|
||||||
|
blanks = 0
|
||||||
np = re.compile(
|
np = re.compile(
|
||||||
"\[\x0303last\.fm\x03\] [A-Za-z0-9_]+ (is listening|last listened) to: \x02.+ - .+\x02 \([0-9]+ plays\)"
|
"\[\x0303last\.fm\x03\] [A-Za-z0-9_]+ (is listening|last listened) to: \x02.+ - .+\x02 \([0-9]+ plays\)( \[.*\])?"
|
||||||
)
|
)
|
||||||
|
|
||||||
ESCAPE_SEQUENCE_RE = re.compile(
|
ESCAPE_SEQUENCE_RE = re.compile(
|
||||||
|
@ -82,7 +83,7 @@ def decode_escapes(s):
|
||||||
|
|
||||||
|
|
||||||
def sucheck(message):
|
def sucheck(message):
|
||||||
return re.search("^(su|sudo).*", message)
|
return re.search("^(su|sudo|(su .*|sudo .*))$", message)
|
||||||
|
|
||||||
|
|
||||||
def ping(ircmsg):
|
def ping(ircmsg):
|
||||||
|
@ -127,7 +128,8 @@ def CTCPHandler(msg: str, sender: str = "", isRaw: bool = False):
|
||||||
return True
|
return True
|
||||||
elif CTCP == "SOURCE":
|
elif CTCP == "SOURCE":
|
||||||
notice(
|
notice(
|
||||||
"\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01", sender,
|
"\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01",
|
||||||
|
sender,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
return True
|
return True
|
||||||
|
@ -156,12 +158,12 @@ def joinserver():
|
||||||
global nicklen
|
global nicklen
|
||||||
nicklen = int(ircmsg.split("NICKLEN=")[1].split(" ")[0])
|
nicklen = int(ircmsg.split("NICKLEN=")[1].split(" ")[0])
|
||||||
print(f"[LOG][{server}] NICKLEN set to {nicklen}")
|
print(f"[LOG][{server}] NICKLEN set to {nicklen}")
|
||||||
if ircmsg.find("Nickname is already in use") != -1:
|
if ircmsg.find("Nickname already in use") != -1:
|
||||||
print(f"[LOG][{server}] My nickname's in use? lemme try that again...")
|
print(f"[LOG][{server}] My nickname's in use? lemme try that again...")
|
||||||
ircsock.send(
|
ircsock.send(
|
||||||
bytes(f"USER {botnick} {botnick} {botnick} {botnick}\n", e)
|
bytes(f"USER {botnick} {botnick} {botnick} {botnick}\n", e)
|
||||||
)
|
)
|
||||||
ircsock.send(bytes(f"NICK {botnick}\n", e))
|
ircsock.send(bytes(f"NICK {botnick+r.randint(0,1000)}\n", e))
|
||||||
if ircmsg.find("PING :") != -1:
|
if ircmsg.find("PING :") != -1:
|
||||||
# pong = "PONG :" + input("Ping?:") + "\n"
|
# pong = "PONG :" + input("Ping?:") + "\n"
|
||||||
# pong = pong.replace("\\\\", "\\")
|
# pong = pong.replace("\\\\", "\\")
|
||||||
|
@ -233,7 +235,7 @@ def op(name, chan):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
global ircmsg, channels, e, gmode, prefix, rebt, gblrebt, lrebt, lgblrebt
|
global ircmsg, channels, e, gmode, prefix, rebt, gblrebt, lrebt, lgblrebt, blanks
|
||||||
joinserver()
|
joinserver()
|
||||||
if "pass" in servers[server]:
|
if "pass" in servers[server]:
|
||||||
sendmsg(f"IDENTIFY {servers[server]['pass']}", "NickServ")
|
sendmsg(f"IDENTIFY {servers[server]['pass']}", "NickServ")
|
||||||
|
@ -244,7 +246,9 @@ def main():
|
||||||
global ircmsg, gmode
|
global ircmsg, gmode
|
||||||
raw = bytes(ircsock.recv(2048).strip(b"\r\n"))
|
raw = bytes(ircsock.recv(2048).strip(b"\r\n"))
|
||||||
ircmsg = raw.decode()
|
ircmsg = raw.decode()
|
||||||
if ircmsg != "":
|
if ircmsg == "":
|
||||||
|
exit(f"[EXIT][{server}] Probably a netsplit")
|
||||||
|
else:
|
||||||
print(raw.lazy_decode(), sep="\n")
|
print(raw.lazy_decode(), sep="\n")
|
||||||
if ircmsg.find("PRIVMSG") != -1:
|
if ircmsg.find("PRIVMSG") != -1:
|
||||||
# Format of ":[Nick]!~[hostname]@[IP Address] PRIVMSG [channel] :[message]”
|
# Format of ":[Nick]!~[hostname]@[IP Address] PRIVMSG [channel] :[message]”
|
||||||
|
@ -262,7 +266,9 @@ def main():
|
||||||
message = ircmsg.split(">", 1)[1].strip()
|
message = ircmsg.split(">", 1)[1].strip()
|
||||||
helpErr = True
|
helpErr = True
|
||||||
else:
|
else:
|
||||||
message = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
|
message = (
|
||||||
|
ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
message = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
|
message = ircmsg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
|
||||||
if name.endswith("dsc"):
|
if name.endswith("dsc"):
|
||||||
|
@ -278,7 +284,9 @@ def main():
|
||||||
if len(name) < nicklen and chan in channels:
|
if len(name) < nicklen and chan in channels:
|
||||||
channels[chan] += 1
|
channels[chan] += 1
|
||||||
elif len(name) > nicklen:
|
elif len(name) > nicklen:
|
||||||
print(f"[LOG][{server}] Name too long ({len(name)} > {nicklen})")
|
print(
|
||||||
|
f"[LOG][{server}] Name too long ({len(name)} > {nicklen})"
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
elif chan not in channels:
|
elif chan not in channels:
|
||||||
print(
|
print(
|
||||||
|
@ -291,7 +299,9 @@ def main():
|
||||||
False,
|
False,
|
||||||
):
|
):
|
||||||
sendmsg(f"Hello {name}!", chan)
|
sendmsg(f"Hello {name}!", chan)
|
||||||
elif mfind(message, ["op me"], False) and name.lower() in adminnames:
|
elif (
|
||||||
|
mfind(message, ["op me"], False) and name.lower() in adminnames
|
||||||
|
):
|
||||||
op(name, chan)
|
op(name, chan)
|
||||||
elif mfind(message, ["amIAdmin"]):
|
elif mfind(message, ["amIAdmin"]):
|
||||||
sendmsg(
|
sendmsg(
|
||||||
|
@ -303,12 +313,16 @@ def main():
|
||||||
sendmsg("List of commands:", name)
|
sendmsg("List of commands:", name)
|
||||||
sendmsg(f'Current prefix is "{prefix}"', name)
|
sendmsg(f'Current prefix is "{prefix}"', name)
|
||||||
sendmsg(f"{prefix}help - Sends this help list", name)
|
sendmsg(f"{prefix}help - Sends this help list", name)
|
||||||
sendmsg(f"{prefix}quote - Sends a random firepup quote", name)
|
sendmsg(
|
||||||
|
f"{prefix}quote - Sends a random firepup quote", name
|
||||||
|
)
|
||||||
sendmsg(
|
sendmsg(
|
||||||
f"{prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question",
|
f"{prefix}(eightball,8ball,8b) [question]? - Asks the magic eightball a question",
|
||||||
name,
|
name,
|
||||||
)
|
)
|
||||||
sendmsg(f"(hi,hello) {botnick} - The bot says hi to you", name)
|
sendmsg(
|
||||||
|
f"(hi,hello) {botnick} - The bot says hi to you", name
|
||||||
|
)
|
||||||
if name.lower() in adminnames:
|
if name.lower() in adminnames:
|
||||||
sendmsg(f"reboot {rebt} - Restarts the bot", name)
|
sendmsg(f"reboot {rebt} - Restarts the bot", name)
|
||||||
sendmsg(exitcode + " - Shuts down the bot", name)
|
sendmsg(exitcode + " - Shuts down the bot", name)
|
||||||
|
@ -334,7 +348,10 @@ def main():
|
||||||
log = open("mastermessages.txt", "r")
|
log = open("mastermessages.txt", "r")
|
||||||
q = log.readlines()
|
q = log.readlines()
|
||||||
sel = decode_escapes(
|
sel = decode_escapes(
|
||||||
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
|
str(r.sample(q, 1))
|
||||||
|
.strip("[]'")
|
||||||
|
.replace("\\n", "")
|
||||||
|
.strip('"')
|
||||||
)
|
)
|
||||||
sendmsg(sel, chan)
|
sendmsg(sel, chan)
|
||||||
log.close()
|
log.close()
|
||||||
|
@ -355,7 +372,9 @@ def main():
|
||||||
log.close()
|
log.close()
|
||||||
else:
|
else:
|
||||||
sendmsg("Please pose a Yes or No question.", chan)
|
sendmsg("Please pose a Yes or No question.", chan)
|
||||||
elif mfind(message, ["debug", "dbg"]) and name.lower() in adminnames:
|
elif (
|
||||||
|
mfind(message, ["debug", "dbg"]) and name.lower() in adminnames
|
||||||
|
):
|
||||||
sendmsg(f"[DEBUG] NICKLEN={nicklen}", chan)
|
sendmsg(f"[DEBUG] NICKLEN={nicklen}", chan)
|
||||||
sendmsg(f"[DEBUG] ADMINS={adminnames}", chan)
|
sendmsg(f"[DEBUG] ADMINS={adminnames}", chan)
|
||||||
sendmsg(f"[DEBUG] CHANNELS={channels}", chan)
|
sendmsg(f"[DEBUG] CHANNELS={channels}", chan)
|
||||||
|
@ -369,7 +388,8 @@ def main():
|
||||||
__import__("os").system(f"python3 -u ircbot.py {server}")
|
__import__("os").system(f"python3 -u ircbot.py {server}")
|
||||||
exit(f"[EXIT][{server}] Inner layer exited or crashed")
|
exit(f"[EXIT][{server}] Inner layer exited or crashed")
|
||||||
elif (
|
elif (
|
||||||
name.lower() in adminnames and message.rstrip().lower() == exitcode
|
name.lower() in adminnames
|
||||||
|
and message.rstrip().lower() == exitcode
|
||||||
):
|
):
|
||||||
sendmsg("oh...okay. :'(", chan)
|
sendmsg("oh...okay. :'(", chan)
|
||||||
for i in channels:
|
for i in channels:
|
||||||
|
@ -382,12 +402,14 @@ def main():
|
||||||
# raise EOFError
|
# raise EOFError
|
||||||
elif sucheck(message):
|
elif sucheck(message):
|
||||||
if name.lower() in adminnames:
|
if name.lower() in adminnames:
|
||||||
sendmsg("Error - system failure, contact system operator", chan)
|
sendmsg(
|
||||||
|
"Error - system failure, contact system operator", chan
|
||||||
|
)
|
||||||
elif "bot" in name.lower():
|
elif "bot" in name.lower():
|
||||||
print(f"[LOG][{server}] lol, no.")
|
print(f"[LOG][{server}] lol, no.")
|
||||||
else:
|
else:
|
||||||
sendmsg("Access Denied", chan)
|
sendmsg("Access Denied", chan)
|
||||||
elif np.search(message) and name == "FireBitBot":
|
elif np.search(message):
|
||||||
x02 = "\x02"
|
x02 = "\x02"
|
||||||
sendmsg(
|
sendmsg(
|
||||||
f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}",
|
f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}",
|
||||||
|
@ -399,14 +421,20 @@ def main():
|
||||||
if CTCP == "ACTION ducks":
|
if CTCP == "ACTION ducks":
|
||||||
sendmsg("\x01ACTION gets hit by a duck\x01", chan)
|
sendmsg("\x01ACTION gets hit by a duck\x01", chan)
|
||||||
elif CTCP.startswith("ACTION ducks"):
|
elif CTCP.startswith("ACTION ducks"):
|
||||||
sendmsg(f"\x01ACTION gets hit by {CTCP.split(' ', 2)[2]}\x01", chan)
|
sendmsg(
|
||||||
|
f"\x01ACTION gets hit by {CTCP.split(' ', 2)[2]}\x01",
|
||||||
|
chan,
|
||||||
|
)
|
||||||
if chan in channels and channels[chan] >= interval:
|
if chan in channels and channels[chan] >= interval:
|
||||||
r.seed()
|
r.seed()
|
||||||
channels[chan] = 0
|
channels[chan] = 0
|
||||||
log = open("mastermessages.txt", "r")
|
log = open("mastermessages.txt", "r")
|
||||||
q = log.readlines()
|
q = log.readlines()
|
||||||
sel = decode_escapes(
|
sel = decode_escapes(
|
||||||
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
|
str(r.sample(q, 1))
|
||||||
|
.strip("[]'")
|
||||||
|
.replace("\\n", "")
|
||||||
|
.strip('"')
|
||||||
)
|
)
|
||||||
sendmsg(f"[QUOTE] {sel}", chan)
|
sendmsg(f"[QUOTE] {sel}", chan)
|
||||||
log.close()
|
log.close()
|
||||||
|
|
Loading…
Reference in a new issue