mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
cleanup
This commit is contained in:
parent
75d38194ca
commit
070b637253
@ -132,7 +132,7 @@ class BotCommands():
|
|||||||
logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e))
|
logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e))
|
||||||
|
|
||||||
# Extra directories
|
# Extra directories
|
||||||
for directory in botconfig.config.core.extra:
|
for directory in botconfig.extra:
|
||||||
filepathlisting.append(directory)
|
filepathlisting.append(directory)
|
||||||
|
|
||||||
return filepathlisting
|
return filepathlisting
|
||||||
|
|||||||
@ -5,7 +5,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
|||||||
from sopel.cli.run import build_parser, get_configuration
|
from sopel.cli.run import build_parser, get_configuration
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import configparser
|
|
||||||
|
|
||||||
|
|
||||||
class BotConfig():
|
class BotConfig():
|
||||||
@ -22,29 +21,14 @@ class BotConfig():
|
|||||||
opts = parser.parse_args(argv)
|
opts = parser.parse_args(argv)
|
||||||
self.config = get_configuration(opts)
|
self.config = get_configuration(opts)
|
||||||
|
|
||||||
# Filename
|
|
||||||
self.filename = self.config.filename
|
|
||||||
|
|
||||||
# load as dict
|
|
||||||
config = configparser.ConfigParser()
|
|
||||||
config.read(self.filename)
|
|
||||||
for each_section in config.sections():
|
|
||||||
if each_section.lower() not in self.dict.keys():
|
|
||||||
self.dict[each_section.lower()] = dict()
|
|
||||||
for (each_key, each_val) in config.items(each_section):
|
|
||||||
if each_key.lower() not in self.dict[each_section.lower()].keys():
|
|
||||||
self.dict[each_section.lower()][each_key.lower()] = each_val
|
|
||||||
|
|
||||||
def define_section(self, name, cls_, validate=True):
|
def define_section(self, name, cls_, validate=True):
|
||||||
return self.config.define_section(name, cls_, validate)
|
return self.config.define_section(name, cls_, validate)
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
''' will only get called for undefined attributes '''
|
''' will only get called for undefined attributes '''
|
||||||
"""We will try to find a core value, or return None"""
|
"""We will try to find a core value, or return None"""
|
||||||
if hasattr(self.config.core, name):
|
if hasattr(self.config, name):
|
||||||
return eval("self.config.core." + name)
|
return eval("self.config.core." + name)
|
||||||
elif name.lower() in self.dict["core"].keys():
|
|
||||||
return self.dict["core"][str(name).lower()]
|
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class BotLogs():
|
|||||||
logtitle = "[" + logtype + "]"
|
logtitle = "[" + logtype + "]"
|
||||||
logmessage = logtitle + " " + logentry
|
logmessage = logtitle + " " + logentry
|
||||||
|
|
||||||
if botconfig.config.core.logging_channel:
|
if botconfig.logging_channel:
|
||||||
self.dict["queue"].append(logmessage)
|
self.dict["queue"].append(logmessage)
|
||||||
|
|
||||||
if stdio:
|
if stdio:
|
||||||
@ -57,7 +57,7 @@ class BotLogs():
|
|||||||
for logtype in self.dict["list"].keys():
|
for logtype in self.dict["list"].keys():
|
||||||
stdio_ignore.append("[" + logtype + "]")
|
stdio_ignore.append("[" + logtype + "]")
|
||||||
|
|
||||||
logfile = os.path.os.path.join(botconfig.config.core.logdir, 'stdio.log')
|
logfile = os.path.os.path.join(botconfig.logdir, 'stdio.log')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log_file_lines = []
|
log_file_lines = []
|
||||||
@ -105,12 +105,12 @@ class BotLogs():
|
|||||||
|
|
||||||
def get_running_pid(self):
|
def get_running_pid(self):
|
||||||
try:
|
try:
|
||||||
filename = "/run/sopel/sopel-" + str(botconfig.config.core.nick) + ".pid"
|
filename = "/run/sopel/sopel-" + str(botconfig.nick) + ".pid"
|
||||||
with open(filename, 'r') as pid_file:
|
with open(filename, 'r') as pid_file:
|
||||||
pidnum = int(pid_file.read())
|
pidnum = int(pid_file.read())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pidnum = e
|
pidnum = e
|
||||||
pidnum = str(os.popen("systemctl show " + str(botconfig.config.core.nick) + " --property=MainPID").read()).split("=")[-1]
|
pidnum = str(os.popen("systemctl show " + str(botconfig.nick) + " --property=MainPID").read()).split("=")[-1]
|
||||||
return pidnum
|
return pidnum
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@ github_dict = {
|
|||||||
def bot_privs(privtype):
|
def bot_privs(privtype):
|
||||||
if privtype == 'owners':
|
if privtype == 'owners':
|
||||||
privtype = 'owner'
|
privtype = 'owner'
|
||||||
botpriveval = eval("botconfig.config.config.core." + privtype)
|
botpriveval = eval("botconfig." + privtype)
|
||||||
if not isinstance(botpriveval, list):
|
if not isinstance(botpriveval, list):
|
||||||
botpriveval = [botpriveval]
|
botpriveval = [botpriveval]
|
||||||
return botpriveval
|
return botpriveval
|
||||||
|
|||||||
@ -10,4 +10,4 @@ import sopel_modules.SpiceBot as SpiceBot
|
|||||||
|
|
||||||
@sopel.module.nickname_commands('database')
|
@sopel.module.nickname_commands('database')
|
||||||
def bot_command_gender(bot, trigger):
|
def bot_command_gender(bot, trigger):
|
||||||
bot.osd("Database is " + SpiceBot.config.dict["core"]["db_type"])
|
bot.osd("Database is " + SpiceBot.config.db_type)
|
||||||
|
|||||||
@ -55,7 +55,7 @@ def setup(bot):
|
|||||||
dir_to_scan.append(api_dir)
|
dir_to_scan.append(api_dir)
|
||||||
|
|
||||||
bot.config.define_section("SopelGifSearch", GifAPIMainSection, validate=False)
|
bot.config.define_section("SopelGifSearch", GifAPIMainSection, validate=False)
|
||||||
SpiceBot.config.config.define_section("SopelGifSearch", GifAPIMainSection, validate=False)
|
SpiceBot.config.define_section("SopelGifSearch", GifAPIMainSection, validate=False)
|
||||||
if bot.config.SopelGifSearch.extra:
|
if bot.config.SopelGifSearch.extra:
|
||||||
dir_to_scan.append(bot.config.SopelGifSearch.extra)
|
dir_to_scan.append(bot.config.SopelGifSearch.extra)
|
||||||
|
|
||||||
@ -63,7 +63,7 @@ def setup(bot):
|
|||||||
|
|
||||||
for gif_api in valid_gif_api_dict.keys():
|
for gif_api in valid_gif_api_dict.keys():
|
||||||
bot.config.define_section(gif_api, GifAPISection, validate=False)
|
bot.config.define_section(gif_api, GifAPISection, validate=False)
|
||||||
SpiceBot.config.config.define_section(gif_api, GifAPISection, validate=False)
|
SpiceBot.config.define_section(gif_api, GifAPISection, validate=False)
|
||||||
apikey = eval("bot.config." + gif_api + ".apikey")
|
apikey = eval("bot.config." + gif_api + ".apikey")
|
||||||
if apikey:
|
if apikey:
|
||||||
valid_gif_api_dict[gif_api]["apikey"] = apikey
|
valid_gif_api_dict[gif_api]["apikey"] = apikey
|
||||||
|
|||||||
@ -42,7 +42,7 @@ def setup(bot):
|
|||||||
# verify config settings for server
|
# verify config settings for server
|
||||||
SpiceBot.logs.log('SpiceBot_Kick', "Checking for config settings")
|
SpiceBot.logs.log('SpiceBot_Kick', "Checking for config settings")
|
||||||
bot.config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
|
bot.config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
|
||||||
SpiceBot.config.config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
|
SpiceBot.config.define_section("SpiceBot_Kick", SpiceBot_Kick, validate=False)
|
||||||
|
|
||||||
|
|
||||||
@module.event('005')
|
@module.event('005')
|
||||||
|
|||||||
@ -18,7 +18,7 @@ def setup(bot):
|
|||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def join_log_channel(bot, trigger):
|
def join_log_channel(bot, trigger):
|
||||||
|
|
||||||
if SpiceBot.config.config.core.logging_channel:
|
if SpiceBot.config.logging_channel:
|
||||||
channel = bot.config.core.logging_channel
|
channel = bot.config.core.logging_channel
|
||||||
if channel not in bot.channels.keys():
|
if channel not in bot.channels.keys():
|
||||||
bot.write(('JOIN', bot.nick, channel))
|
bot.write(('JOIN', bot.nick, channel))
|
||||||
|
|||||||
@ -25,7 +25,7 @@ def configure(config):
|
|||||||
def setup(bot):
|
def setup(bot):
|
||||||
SpiceBot.logs.log('SpiceBot_Update', "Initial Setup processing")
|
SpiceBot.logs.log('SpiceBot_Update', "Initial Setup processing")
|
||||||
bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
||||||
SpiceBot.config.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
SpiceBot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
||||||
|
|
||||||
|
|
||||||
@SpiceBot.prerun.prerun('nickname')
|
@SpiceBot.prerun.prerun('nickname')
|
||||||
|
|||||||
@ -50,7 +50,7 @@ def setup(bot):
|
|||||||
# verify config settings for server
|
# verify config settings for server
|
||||||
SpiceBot.logs.log('SpiceBot_OSD', "Checking for config settings")
|
SpiceBot.logs.log('SpiceBot_OSD', "Checking for config settings")
|
||||||
bot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
|
bot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
|
||||||
SpiceBot.config.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
|
SpiceBot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
|
||||||
|
|
||||||
|
|
||||||
@module.event('005')
|
@module.event('005')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user