Replaced double quotes to single quotes where possible.
This commit is contained in:
parent
c4ce053e69
commit
e95947d2d3
3 changed files with 16 additions and 13 deletions
11
src/bot.py
11
src/bot.py
|
@ -54,11 +54,11 @@ class Bot:
|
||||||
|
|
||||||
def load_plugins(self):
|
def load_plugins(self):
|
||||||
self.plugins = []
|
self.plugins = []
|
||||||
plugin_folder = "./plugins"
|
plugin_folder = './plugins'
|
||||||
for filename in os.listdir(plugin_folder):
|
for filename in os.listdir(plugin_folder):
|
||||||
if filename.endswith('.py'):
|
if filename.endswith('.py'):
|
||||||
filepath = os.path.join(plugin_folder, filename)
|
filepath = os.path.join(plugin_folder, filename)
|
||||||
spec = importlib.util.spec_from_file_location("module.name", filepath)
|
spec = importlib.util.spec_from_file_location('module.name', filepath)
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(module)
|
spec.loader.exec_module(module)
|
||||||
for name, obj in inspect.getmembers(module):
|
for name, obj in inspect.getmembers(module):
|
||||||
|
@ -125,9 +125,10 @@ class Bot:
|
||||||
try:
|
try:
|
||||||
self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
|
||||||
if str(self.config["Connection"].get("Port"))[:1] == '+':
|
if str(self.config['Connection'].get('Port'))[:1] == '+':
|
||||||
context = ssl.create_default_context()
|
context = ssl.create_default_context()
|
||||||
self.ircsock = context.wrap_socket(self.ircsock, server_hostname=self.config["Connection"].get("Hostname"))
|
self.ircsock = context.wrap_socket(self.ircsock,
|
||||||
|
server_hostname=self.config['Connection'].get('Hostname'))
|
||||||
port = int(self.config['Connection'].get('Port')[1:])
|
port = int(self.config['Connection'].get('Port')[1:])
|
||||||
else:
|
else:
|
||||||
port = int(self.config['Connection'].get('Port'))
|
port = int(self.config['Connection'].get('Port'))
|
||||||
|
@ -138,7 +139,7 @@ class Bot:
|
||||||
self.ircsock.connect_ex((self.config['Connection'].get('Hostname'), port))
|
self.ircsock.connect_ex((self.config['Connection'].get('Hostname'), port))
|
||||||
self.ircsend(f'NICK {self.config["Connection"].get("Nick")}')
|
self.ircsend(f'NICK {self.config["Connection"].get("Nick")}')
|
||||||
self.ircsend(f'USER {self.config["Connection"].get("Ident")} * * :{self.config["Connection"].get("Name")}')
|
self.ircsend(f'USER {self.config["Connection"].get("Ident")} * * :{self.config["Connection"].get("Name")}')
|
||||||
if self.config["SASL"].get("UseSASL"):
|
if self.config['SASL'].get('UseSASL'):
|
||||||
self.ircsend('CAP REQ :sasl')
|
self.ircsend('CAP REQ :sasl')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.error(f"Error establishing connection: {e}")
|
self.logger.error(f"Error establishing connection: {e}")
|
||||||
|
|
|
@ -10,7 +10,7 @@ class ChannelManager:
|
||||||
self.channels = self._load_channels()
|
self.channels = self._load_channels()
|
||||||
|
|
||||||
def _load_channels(self):
|
def _load_channels(self):
|
||||||
os.makedirs("data", exist_ok=True)
|
os.makedirs('data', exist_ok=True)
|
||||||
if not path.exists('data/channels.json'):
|
if not path.exists('data/channels.json'):
|
||||||
with open('data/channels.json', 'w') as f:
|
with open('data/channels.json', 'w') as f:
|
||||||
json.dump([], f)
|
json.dump([], f)
|
||||||
|
@ -19,10 +19,10 @@ class ChannelManager:
|
||||||
with open('data/channels.json', 'r') as f:
|
with open('data/channels.json', 'r') as f:
|
||||||
return json.load(f)
|
return json.load(f)
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
print(f"Error decoding JSON: {e}")
|
print(f'Error decoding JSON: {e}')
|
||||||
return []
|
return []
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error loading channels: {e}")
|
print(f'Error loading channels: {e}')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def save_channel(self, channel):
|
def save_channel(self, channel):
|
||||||
|
@ -38,12 +38,12 @@ class ChannelManager:
|
||||||
self._write_channels()
|
self._write_channels()
|
||||||
|
|
||||||
def _write_channels(self):
|
def _write_channels(self):
|
||||||
os.makedirs("data", exist_ok=True)
|
os.makedirs('data', exist_ok=True)
|
||||||
try:
|
try:
|
||||||
with open('data/channels.json', 'w') as f:
|
with open('data/channels.json', 'w') as f:
|
||||||
json.dump(self.channels, f)
|
json.dump(self.channels, f)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error saving channels: {e}")
|
print(f'Error saving channels: {e}')
|
||||||
|
|
||||||
def get_channels(self):
|
def get_channels(self):
|
||||||
return self.channels
|
return self.channels
|
||||||
|
|
|
@ -26,12 +26,14 @@ def handle_authenticate(args, config, ircsend):
|
||||||
ircsend (function): Function to send IRC commands
|
ircsend (function): Function to send IRC commands
|
||||||
"""
|
"""
|
||||||
if args[0] == '+':
|
if args[0] == '+':
|
||||||
if "SASLNick" in config['SASL'] and "SASLPassword" in config['SASL']:
|
if 'SASLNick' in config['SASL'] and 'SASLPassword' in config['SASL']:
|
||||||
authpass = f"{config['SASL']['SASLNick']}{NULL_BYTE}{config['SASL']['SASLNick']}{NULL_BYTE}{config['SASL']['SASLPassword']}"
|
authpass = (f'{config["SASL"]["SASLNick"]}{NULL_BYTE}'
|
||||||
|
f'{config["SASL"]["SASLNick"]}{NULL_BYTE}'
|
||||||
|
f'{config["SASL"]["SASLPassword"]}')
|
||||||
ap_encoded = base64.b64encode(authpass.encode(ENCODING)).decode(ENCODING)
|
ap_encoded = base64.b64encode(authpass.encode(ENCODING)).decode(ENCODING)
|
||||||
ircsend(f'AUTHENTICATE {ap_encoded}')
|
ircsend(f'AUTHENTICATE {ap_encoded}')
|
||||||
else:
|
else:
|
||||||
raise KeyError("SASLNICK and/or SASLPASS not found in config")
|
raise KeyError('SASLNICK and/or SASLPASS not found in config')
|
||||||
|
|
||||||
|
|
||||||
def handle_903(ircsend):
|
def handle_903(ircsend):
|
||||||
|
|
Loading…
Add table
Reference in a new issue