Reload support & minor fixes
This commit is contained in:
parent
fadd8539e6
commit
1b48269d17
2 changed files with 40 additions and 26 deletions
45
bot.py
45
bot.py
|
@ -1,17 +1,17 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from socket import socket, AF_INET, SOCK_STREAM
|
from socket import socket, AF_INET, SOCK_STREAM
|
||||||
from overrides import bytes, bbytes
|
from overrides import bytes, bbytes
|
||||||
from logs import log
|
import logs
|
||||||
import re
|
import re
|
||||||
from typing import NoReturn, Union
|
from typing import NoReturn, Union
|
||||||
from config import npbase, servers, __version__, prefix
|
|
||||||
import commands as cmds
|
import commands as cmds
|
||||||
from config import decode_escapes, servers
|
import config as conf
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from importlib import reload
|
||||||
|
|
||||||
def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
|
def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
|
||||||
if usePrefix:
|
if usePrefix:
|
||||||
return any(message[: len(match) + 1] == prefix + match for match in find)
|
return any(message[: len(match) + 1] == conf.prefix + match for match in find)
|
||||||
else:
|
else:
|
||||||
return any(message[: len(match)] == match for match in find)
|
return any(message[: len(match)] == match for match in find)
|
||||||
|
|
||||||
|
@ -20,16 +20,17 @@ class bot:
|
||||||
self.gmode = False
|
self.gmode = False
|
||||||
self.server = server
|
self.server = server
|
||||||
self.nicklen = 30
|
self.nicklen = 30
|
||||||
self.address = servers[server]["address"]
|
self.address = conf.servers[server]["address"]
|
||||||
self.port = servers[server]["port"] if "port" in servers[server] else 6667
|
self.port = conf.servers[server]["port"] if "port" in conf.servers[server] else 6667
|
||||||
self.channels = servers[server]["channels"]
|
self.channels = conf.servers[server]["channels"]
|
||||||
self.interval = (
|
self.interval = (
|
||||||
servers[server]["interval"] if "interval" in servers[server] else 50
|
conf.servers[server]["interval"] if "interval" in conf.servers[server] else 50
|
||||||
)
|
)
|
||||||
|
self.__version__ = conf.__version__
|
||||||
self.nick = "FireBot"
|
self.nick = "FireBot"
|
||||||
self.rebt = "fire"
|
self.rebt = "fire"
|
||||||
self.gblrebt = "all"
|
self.gblrebt = "all"
|
||||||
self.adminnames = servers[server]["admins"]
|
self.adminnames = conf.servers[server]["admins"]
|
||||||
self.exitcode = f"bye {self.nick.lower()}"
|
self.exitcode = f"bye {self.nick.lower()}"
|
||||||
self.queue = []
|
self.queue = []
|
||||||
self.sock = socket(AF_INET, SOCK_STREAM)
|
self.sock = socket(AF_INET, SOCK_STREAM)
|
||||||
|
@ -135,10 +136,10 @@ class bot:
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def log(self, message: object, level: str = "LOG") -> None:
|
def log(self, message: object, level: str = "LOG") -> None:
|
||||||
log(message, self.server)
|
logs.log(message, self.server)
|
||||||
|
|
||||||
def exit(self, message: object) -> NoReturn:
|
def exit(self, message: object) -> NoReturn:
|
||||||
log(message, self.server, "EXIT")
|
logs.log(message, self.server, "EXIT")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
def CTCP(self, msg: str, sender: str = "", isRaw: bool = False) -> bool:
|
def CTCP(self, msg: str, sender: str = "", isRaw: bool = False) -> bool:
|
||||||
|
@ -149,7 +150,7 @@ class bot:
|
||||||
self.log(f"Responding to CTCP \"{kind}\" from {sender}")
|
self.log(f"Responding to CTCP \"{kind}\" from {sender}")
|
||||||
if kind == "VERSION":
|
if kind == "VERSION":
|
||||||
self.notice(
|
self.notice(
|
||||||
f"\x01VERSION FireBot {__version__} (https://git.amcforum.wiki/Firepup650/fire-ircbot)\x01",
|
f"\x01VERSION FireBot {conf.__version__} (https://git.amcforum.wiki/Firepup650/fire-ircbot)\x01",
|
||||||
sender,
|
sender,
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
@ -200,8 +201,8 @@ class bot:
|
||||||
def mainloop(self) -> NoReturn:
|
def mainloop(self) -> NoReturn:
|
||||||
self.log("Starting connection..")
|
self.log("Starting connection..")
|
||||||
self.connect()
|
self.connect()
|
||||||
if "pass" in servers[self.server]:
|
if "pass" in conf.servers[self.server]:
|
||||||
self.msg(f"IDENTIFY FireBot {servers[self.server]['pass']}", "NickServ")
|
self.msg(f"IDENTIFY FireBot {conf.servers[self.server]['pass']}", "NickServ")
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
for chan in self.channels:
|
for chan in self.channels:
|
||||||
self.join(chan, "null", False)
|
self.join(chan, "null", False)
|
||||||
|
@ -252,6 +253,8 @@ class bot:
|
||||||
f"Channel not in channels ({chan} not in {self.channels})",
|
f"Channel not in channels ({chan} not in {self.channels})",
|
||||||
"WARN",
|
"WARN",
|
||||||
)
|
)
|
||||||
|
if not chan.startswith(("#", "+", "&")):
|
||||||
|
chan = name
|
||||||
else:
|
else:
|
||||||
self.channels[chan] += 1
|
self.channels[chan] += 1
|
||||||
if "goat" in name.lower() and self.gmode == True:
|
if "goat" in name.lower() and self.gmode == True:
|
||||||
|
@ -277,9 +280,21 @@ class bot:
|
||||||
),
|
),
|
||||||
message,
|
message,
|
||||||
):
|
):
|
||||||
|
if ("admin" in cmds.data[cmd] and cmds.data[cmd]["admin"]) and name not in self.adminnames:
|
||||||
|
self.msg(f"Sorry {name}, you don't have permission to use {cmd}.", chan)
|
||||||
|
else:
|
||||||
cmds.call[check](self, chan, name, message)
|
cmds.call[check](self, chan, name, message)
|
||||||
handled = True
|
handled = True
|
||||||
break
|
break
|
||||||
|
if not handled and mfind(message, ["reload"]):
|
||||||
|
if name in self.adminnames:
|
||||||
|
reload(conf)
|
||||||
|
reload(cmds)
|
||||||
|
self.__version__ = conf.__version__
|
||||||
|
self.msg("Reloaded config and commands", chan)
|
||||||
|
else:
|
||||||
|
self.msg(f"Sorry {name}, you don't have permission to use reload.", chan)
|
||||||
|
handled = True
|
||||||
if not handled and len(message.split("\x01")) == 3:
|
if not handled and len(message.split("\x01")) == 3:
|
||||||
if not self.CTCP(message, name):
|
if not self.CTCP(message, name):
|
||||||
CTCP = message.split("\x01")[1]
|
CTCP = message.split("\x01")[1]
|
||||||
|
@ -295,7 +310,7 @@ class bot:
|
||||||
self.channels[chan] = 0
|
self.channels[chan] = 0
|
||||||
mm = open("mastermessages.txt", "r")
|
mm = open("mastermessages.txt", "r")
|
||||||
q = mm.readlines()
|
q = mm.readlines()
|
||||||
sel = decode_escapes(
|
sel = config.decode_escapes(
|
||||||
str(r.sample(q, 1))
|
str(r.sample(q, 1))
|
||||||
.strip("[]'")
|
.strip("[]'")
|
||||||
.replace("\\n", "")
|
.replace("\\n", "")
|
||||||
|
|
19
commands.py
19
commands.py
|
@ -5,6 +5,7 @@ import random as r
|
||||||
def goat(bot, chan: str, name: str, message: str) -> None:
|
def goat(bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.log("GOAT DETECTED")
|
bot.log("GOAT DETECTED")
|
||||||
bot.msg("Hello Goat", chan)
|
bot.msg("Hello Goat", chan)
|
||||||
|
bot.gmode = False
|
||||||
|
|
||||||
|
|
||||||
def botlist(bot, chan: str, name: str, message: str) -> None:
|
def botlist(bot, chan: str, name: str, message: str) -> None:
|
||||||
|
@ -95,7 +96,6 @@ def quote(bot, chan: str, name: str, message: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def join(bot, chan: str, name: str, message: str) -> None:
|
def join(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name.lower() in bot.adminnames:
|
|
||||||
newchan = message.split(" ", 1)[1].strip()
|
newchan = message.split(" ", 1)[1].strip()
|
||||||
bot.join(newchan, chan)
|
bot.join(newchan, chan)
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ def eball(bot, chan: str, name: str, message: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def debug(bot, chan: str, name: str, message: str) -> None:
|
def debug(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name.lower() in bot.adminnames:
|
bot.msg(f"[DEBUG] VERSION={bot.__version__}", chan)
|
||||||
bot.msg(f"[DEBUG] NICKLEN={bot.nicklen}", chan)
|
bot.msg(f"[DEBUG] NICKLEN={bot.nicklen}", chan)
|
||||||
bot.msg(f"[DEBUG] ADMINS={bot.adminnames}", chan)
|
bot.msg(f"[DEBUG] ADMINS={bot.adminnames}", chan)
|
||||||
bot.msg(f"[DEBUG] CHANNELS={bot.channels}", chan)
|
bot.msg(f"[DEBUG] CHANNELS={bot.channels}", chan)
|
||||||
|
@ -123,7 +123,6 @@ def raw(bot, chan: str, name: str, message: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def reboot(bot, chan: str, name: str, message: str) -> None:
|
def reboot(bot, chan: str, name: str, message: str) -> None:
|
||||||
if name.lower() in bot.adminnames:
|
|
||||||
bot.send("QUIT :Rebooting\n")
|
bot.send("QUIT :Rebooting\n")
|
||||||
bot.exit("Reboot")
|
bot.exit("Reboot")
|
||||||
|
|
||||||
|
@ -151,19 +150,19 @@ data = {
|
||||||
"bugs bugs bugs": {"prefix": False, "aliases": []},
|
"bugs bugs bugs": {"prefix": False, "aliases": []},
|
||||||
"hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]},
|
"hi $BOTNICK": {"prefix": False, "aliases": ["hello $BOTNICK"]},
|
||||||
# [npbase, su]
|
# [npbase, su]
|
||||||
"restart": {"prefix": True, "aliases": ["reboot"]},
|
"restart": {"prefix": True, "aliases": ["reboot"], "admin": True},
|
||||||
"uptime": {"prefix": True, "aliases": []},
|
"uptime": {"prefix": True, "aliases": []},
|
||||||
"raw ": {"prefix": True, "aliases": ["cmd "]},
|
"raw ": {"prefix": True, "aliases": ["cmd "], "admin": True},
|
||||||
"debug": {"prefix": True, "aliases": ["dbg"]},
|
"debug": {"prefix": True, "aliases": ["dbg"], "admin": True},
|
||||||
"8ball": {"prefix": True, "aliases": ["eightball", "8b"]},
|
"8ball": {"prefix": True, "aliases": ["eightball", "8b"]},
|
||||||
"join ": {"prefix": True, "aliases": []},
|
"join ": {"prefix": True, "aliases": [], "admin": True},
|
||||||
"quote": {"prefix": True, "aliases": ["q"]},
|
"quote": {"prefix": True, "aliases": ["q"]},
|
||||||
"goat.mode.activate": {"prefix": True, "aliases": []},
|
"goat.mode.activate": {"prefix": True, "aliases": [], "admin": True},
|
||||||
"goat.mode.deactivate": {"prefix": True, "aliases": []},
|
"goat.mode.deactivate": {"prefix": True, "aliases": [], "admin": True},
|
||||||
"help": {"prefix": True, "aliases": []},
|
"help": {"prefix": True, "aliases": []},
|
||||||
"amIAdmin": {"prefix": True, "aliases": []},
|
"amIAdmin": {"prefix": True, "aliases": []},
|
||||||
"ping": {"prefix": True, "aliases": []},
|
"ping": {"prefix": True, "aliases": []},
|
||||||
"op me": {"prefix": False, "aliases": []},
|
"op me": {"prefix": False, "aliases": [], "admin": True},
|
||||||
}
|
}
|
||||||
checks = [npbase, su]
|
checks = [npbase, su]
|
||||||
call = {
|
call = {
|
||||||
|
|
Loading…
Reference in a new issue