Lots of work, really too much for one commit.
This commit is contained in:
parent
1555ea16c0
commit
f5d4071fc2
1 changed files with 56 additions and 30 deletions
86
ircbot.py
86
ircbot.py
|
@ -24,8 +24,9 @@ servers = {
|
||||||
"ircnow": {
|
"ircnow": {
|
||||||
"address": "localhost",
|
"address": "localhost",
|
||||||
"port": 6601,
|
"port": 6601,
|
||||||
|
"interval": 200,
|
||||||
"channels": {"#random": 0, "#dice": 0, "#offtopic": 0, botnick: 0},
|
"channels": {"#random": 0, "#dice": 0, "#offtopic": 0, botnick: 0},
|
||||||
"admins": ["firepup", "firepup650", "h|thelounge"],
|
"admins": ["firepup", "h|thelounge"],
|
||||||
},
|
},
|
||||||
"efnet": {
|
"efnet": {
|
||||||
"address": "irc.servercentral.net",
|
"address": "irc.servercentral.net",
|
||||||
|
@ -45,6 +46,7 @@ nicklen = 30
|
||||||
address = servers[server]["address"]
|
address = servers[server]["address"]
|
||||||
port = servers[server]["port"] if "port" in servers[server] else 6667
|
port = servers[server]["port"] if "port" in servers[server] else 6667
|
||||||
channels = servers[server]["channels"]
|
channels = servers[server]["channels"]
|
||||||
|
interval = servers[server]["interval"] if "interval" in servers[server] else 50
|
||||||
encoding = "UTF-8"
|
encoding = "UTF-8"
|
||||||
prefix = "."
|
prefix = "."
|
||||||
rebt = "fire"
|
rebt = "fire"
|
||||||
|
@ -83,6 +85,51 @@ def sucheck(message):
|
||||||
return re.search("^(su|sudo).*", message)
|
return re.search("^(su|sudo).*", message)
|
||||||
|
|
||||||
|
|
||||||
|
def ping(ircmsg):
|
||||||
|
pong = f"PONG :{ircmsg.split('PING :')[1]}\n"
|
||||||
|
ircsock.send(bytes(pong, e))
|
||||||
|
print(pong, end="")
|
||||||
|
|
||||||
|
|
||||||
|
def sendmsg(msg, target):
|
||||||
|
if target != "NickServ" and not mfind(msg, ["IDENTIFY"], False):
|
||||||
|
print(
|
||||||
|
f"[LOG][{server}] Sending {bytes(msg.encode()).lazy_decode()} to {target}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
print(f"[LOG][{server}] Identifying myself...")
|
||||||
|
ircsock.send(bytes(f"PRIVMSG {target} :{msg}\n", e))
|
||||||
|
|
||||||
|
|
||||||
|
def notice(msg, target):
|
||||||
|
print(
|
||||||
|
f"[LOG][{server}] Sending {bytes(msg.encode()).lazy_decode()} to {target} (NOTICE)"
|
||||||
|
)
|
||||||
|
ircsock.send(bytes(f"NOTICE {target} :{msg}\n", e))
|
||||||
|
|
||||||
|
|
||||||
|
def CTCPHandler(msg: str, sender: str = "", isRaw: bool = False):
|
||||||
|
if isRaw:
|
||||||
|
sender = msg.split("!", 1)[0][1:]
|
||||||
|
message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
|
||||||
|
CTCP = msg.split("\x01")[1]
|
||||||
|
if CTCP == "VERSION":
|
||||||
|
notice(
|
||||||
|
f"\x01VERSION FireBot {__version__} (https://git.amcforum.wiki/Firepup650/fire-ircbot)\x01",
|
||||||
|
sender,
|
||||||
|
)
|
||||||
|
elif CTCP == "USERINFO":
|
||||||
|
notice("\x01USERINFO FireBot (Firepup's bot)\x01", sender)
|
||||||
|
elif CTCP == "SOURCE":
|
||||||
|
notice(
|
||||||
|
"\x01SOURCE https://git.amcforum.wiki/Firepup650/fire-ircbot\x01", sender
|
||||||
|
)
|
||||||
|
elif CTCP == "FINGER":
|
||||||
|
notice(f"\x01FINGER Firepup's bot\x01", sender)
|
||||||
|
elif CTCP == "CLIENTINFO":
|
||||||
|
notice(f"\x01CLIENTINFO ACTION VERSION USERINFO SOURCE FINGER", sender)
|
||||||
|
|
||||||
|
|
||||||
def joinserver():
|
def joinserver():
|
||||||
global e, nicklen
|
global e, nicklen
|
||||||
ircsock.connect((address, port))
|
ircsock.connect((address, port))
|
||||||
|
@ -108,9 +155,9 @@ def joinserver():
|
||||||
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("\\\\", "\\")
|
||||||
pong = f"PONG :{ircmsg.split('PING :')[1]}\n"
|
ping(ircmsg)
|
||||||
print(pong, end="")
|
if len(ircmsg.split("\x01")) == 3:
|
||||||
ircsock.send(bytes(pong, e))
|
CTCPHandler(ircmsg, isRaw=True)
|
||||||
if ircmsg.find("Closing Link") != -1:
|
if ircmsg.find("Closing Link") != -1:
|
||||||
print(f"[LOG][{server}] I tried.")
|
print(f"[LOG][{server}] I tried.")
|
||||||
exit(f"[EXIT][{server}] Closing Link")
|
exit(f"[EXIT][{server}] Closing Link")
|
||||||
|
@ -124,29 +171,6 @@ def mfind(message: str, find: list, usePrefix: bool = True):
|
||||||
return any(message[: len(match)] == match for match in find)
|
return any(message[: len(match)] == match for match in find)
|
||||||
|
|
||||||
|
|
||||||
def ping(ircmsg):
|
|
||||||
pong = f"PONG :{ircmsg.split(':')[1]}\n"
|
|
||||||
ircsock.send(bytes(pong, e))
|
|
||||||
print(pong, end="")
|
|
||||||
|
|
||||||
|
|
||||||
def sendmsg(msg, target):
|
|
||||||
if target != "NickServ" and not mfind(msg, ["IDENTIFY"], False):
|
|
||||||
print(
|
|
||||||
f"[LOG][{server}] Sending {bytes(msg.encode()).lazy_decode()} to {target}"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
print(f"[LOG][{server}] Identifying myself...")
|
|
||||||
ircsock.send(bytes(f"PRIVMSG {target} :{msg}\n", e))
|
|
||||||
|
|
||||||
|
|
||||||
def notice(msg, target):
|
|
||||||
print(
|
|
||||||
f"[LOG][{server}] Sending {bytes(msg.encode()).lazy_decode()} to {target} (NOTICE)"
|
|
||||||
)
|
|
||||||
ircsock.send(bytes(f"NOTICE {target} :{msg}\n", e))
|
|
||||||
|
|
||||||
|
|
||||||
def joinchan(chan: str, origin: str, chanList: dict, lock: bool = True):
|
def joinchan(chan: str, origin: str, chanList: dict, lock: bool = True):
|
||||||
chan = chan.replace(" ", "")
|
chan = chan.replace(" ", "")
|
||||||
if "," in chan:
|
if "," in chan:
|
||||||
|
@ -170,6 +194,8 @@ def joinchan(chan: str, origin: str, chanList: dict, lock: bool = True):
|
||||||
print(bytes(ircmsg.encode()).lazy_decode())
|
print(bytes(ircmsg.encode()).lazy_decode())
|
||||||
if ircmsg.find("PING :") != -1:
|
if ircmsg.find("PING :") != -1:
|
||||||
ping()
|
ping()
|
||||||
|
if len(ircmsg.split("\x01")) == 3:
|
||||||
|
CTCPHandler(ircmsg, isRaw=True)
|
||||||
if ircmsg.find("No such channel") != -1:
|
if ircmsg.find("No such channel") != -1:
|
||||||
print(f"[LOG][{server}] Joining {chan} failed (DM)")
|
print(f"[LOG][{server}] Joining {chan} failed (DM)")
|
||||||
if origin != "null":
|
if origin != "null":
|
||||||
|
@ -357,9 +383,9 @@ def main():
|
||||||
f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}",
|
f"f.sp {message.split(':')[1].split('(')[0].strip(f' {x02}')}",
|
||||||
chan,
|
chan,
|
||||||
)
|
)
|
||||||
elif message == "\x01VERSION\x01":
|
elif len(message.split("\x01")) == 3:
|
||||||
notice(f"\x01VERSION FireBot {__version__}\x01", name)
|
CTCPHandler(message, name)
|
||||||
if chan in channels and channels[chan] >= 50:
|
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")
|
||||||
|
|
Loading…
Reference in a new issue