I forgot what I added, lol, nick change, reloadable config...ish, exec, anything else? lol
This commit is contained in:
parent
68ee237c14
commit
e96f884424
8
bot.py
8
bot.py
|
@ -3,6 +3,7 @@ import ircstates,socket,ssl
|
|||
|
||||
from config import *
|
||||
from stuff import stuff
|
||||
from util import Util
|
||||
|
||||
class bot:
|
||||
server=ircstates.Server(config.server.name)
|
||||
|
@ -16,8 +17,15 @@ class bot:
|
|||
with socket.create_connection((self.host, self.port)) as sock_raw:
|
||||
ctx=ssl.create_default_context()
|
||||
with ctx.wrap_socket(sock_raw, server_hostname=self.host) as sock:
|
||||
try:
|
||||
util=Util(sock,config)
|
||||
stuff(self,sock)
|
||||
except KeyboardInterrupt: util.quit("^C")
|
||||
else:
|
||||
with socket.create_connection((self.host, self.port)) as sock:
|
||||
try:
|
||||
util=Util(sock,config)
|
||||
stuff(self,sock)
|
||||
except KeyboardInterrupt: util.quit("^C")
|
||||
print("starting bot...")
|
||||
bot()
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
from util import Util
|
||||
class Command:
|
||||
def __init__(self,sock):
|
||||
def __init__(self,sock,config):
|
||||
self.sock=sock
|
||||
self.util=Util(sock)
|
||||
self.config=config
|
||||
self.util=Util(sock,config)
|
||||
def mesg(self,msg): self.util.mesg(msg)
|
||||
def err_perm(self,level="admin"): mesg("Error: insufficient privileges, you lack {level} access")
|
||||
def exec_cmd(self,command,extra=[None]):
|
||||
|
|
|
@ -24,4 +24,4 @@ class config:
|
|||
class cmd:
|
||||
prefixes=["6","'"]
|
||||
enabled_commands=["help","echo"]
|
||||
admin_commands=["eval","quit","reload"]
|
||||
admin_commands=["eval","exec","quit"]
|
||||
|
|
31
stuff.py
31
stuff.py
|
@ -5,23 +5,29 @@ from commands import Command
|
|||
import sys, importlib
|
||||
def stuff(bot,sock):
|
||||
config=Config
|
||||
chan=config.server.channel
|
||||
util=Util(sock)
|
||||
command=Command(sock)
|
||||
util=Util(sock,config)
|
||||
command=Command(sock,config)
|
||||
server=bot.server
|
||||
send=util.send
|
||||
quit=util.quit
|
||||
mesg=util.mesg
|
||||
|
||||
server_caps=[]
|
||||
wanted_caps=config.capabilities
|
||||
chan=config.server.channel #autojoin channel
|
||||
is_pm=False
|
||||
mode="init"
|
||||
def configure():
|
||||
config=importlib.reload(sys.modules["config"]).config
|
||||
command=importlib.reload(sys.modules["commands"]).Command(sock,config)
|
||||
util=Util(sock,config)
|
||||
prefixes=config.cmd.prefixes
|
||||
admin_accounts=config.admin.accounts
|
||||
admin_users=config.admin.hostmasks
|
||||
is_pm=False
|
||||
enabled_commands=config.cmd.enabled_commands
|
||||
admin_commands=config.cmd.admin_commands
|
||||
return command,config,util,prefixes,admin_accounts,admin_users,enabled_commands,admin_commands
|
||||
|
||||
command,config,util,prefixes,admin_accounts,admin_users,enabled_commands,admin_commands=configure()
|
||||
|
||||
send(irctokens.build("NICK", [config.self.nick]).format())
|
||||
send(irctokens.build("USER", [config.self.username,"0","*",config.self.realname]).format())
|
||||
|
@ -54,6 +60,9 @@ def stuff(bot,sock):
|
|||
send(irctokens.build("JOIN", [chan]).format())
|
||||
mode="normal"
|
||||
elif mode=="normal":
|
||||
if line.command == "433":
|
||||
mesg("nick in use!",chan)
|
||||
util.nick(config.self.nick)
|
||||
if line.command == "INVITE":
|
||||
send(irctokens.build("JOIN", [line.params[1]]).format())
|
||||
elif line.command == "PRIVMSG":
|
||||
|
@ -84,6 +93,7 @@ def stuff(bot,sock):
|
|||
command.pm=is_pm
|
||||
command.cmd=cmd
|
||||
command.admin=is_adm
|
||||
command.config=config
|
||||
if cmd.startswith("echo "):
|
||||
command.exec_cmd("echo")
|
||||
if cmd=="help":
|
||||
|
@ -96,9 +106,7 @@ def stuff(bot,sock):
|
|||
elif is_adm and (cmd.startswith("q ") or cmd.startswith("quit")):
|
||||
quit(cmd.split(" ",1)[1])
|
||||
elif is_adm and cmd.startswith("reload"):
|
||||
# command.exec_cmd("reload")
|
||||
command=importlib.reload(sys.modules["commands"]).Command(sock)
|
||||
config=importlib.reload(sys.modules["config"]).config
|
||||
command,config,util,prefixes,admin_accounts,admin_users,enabled_command,admin_commands=configure()
|
||||
mesg("reloaded")
|
||||
elif cmd.startswith("eval "):
|
||||
if(is_adm):
|
||||
|
@ -107,3 +115,10 @@ def stuff(bot,sock):
|
|||
except Exception as e:
|
||||
mesg("Error: "+str(e))
|
||||
else: mesg("Error: you're not authorized to eval")
|
||||
elif cmd.startswith("exec "):
|
||||
if(is_adm):
|
||||
try:
|
||||
result=exec(cmd[len("exec "):].strip() or "None")
|
||||
except Exception as e:
|
||||
mesg("Error: "+str(e))
|
||||
else: mesg("Error: you're not authorized to exec")
|
||||
|
|
6
util.py
6
util.py
|
@ -1,7 +1,8 @@
|
|||
import irctokens
|
||||
class Util:
|
||||
def __init__(self,sock):
|
||||
def __init__(self,sock,config):
|
||||
self.sock=sock
|
||||
self.config=config
|
||||
self.target=""
|
||||
def send(self,raw: str):
|
||||
print(f"> {raw}")
|
||||
|
@ -9,6 +10,9 @@ class Util:
|
|||
def quit(self,msg=None):
|
||||
if msg!=None: self.send("QUIT :"+msg)
|
||||
else: self.send("QUIT")
|
||||
def nick(self,nick=None):
|
||||
if nick==None: self.send("NICK "+self.config.self.nick)
|
||||
else: self.send("NICK "+nick)
|
||||
def mesg(self,msg: str,t=None):
|
||||
if t==None: t=self.target
|
||||
msg=msg.partition("\n")[0]
|
||||
|
|
Loading…
Reference in New Issue