mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
database is better than brn file
This commit is contained in:
parent
b0272d014e
commit
8eebebe7b4
@ -10,7 +10,6 @@ import os
|
||||
import tempfile
|
||||
import aiml
|
||||
|
||||
from .Config import config as botconfig
|
||||
from .Database import db as botdb
|
||||
|
||||
|
||||
@ -31,35 +30,26 @@ class SpiceBot_AI():
|
||||
self.load_brain()
|
||||
|
||||
def load_brain(self):
|
||||
if os.path.isfile(botconfig.config.aibrain):
|
||||
self.aiml_kernel.bootstrap(brainFile=botconfig.config.aibrain)
|
||||
import sopel_modules
|
||||
for plugin_dir in set(sopel_modules.__path__):
|
||||
configsdir = os.path.join(plugin_dir, "SpiceBot_Configs")
|
||||
aimldir = os.path.join(configsdir, "aiml")
|
||||
aimlstarter = tempfile.mkstemp()[1]
|
||||
with open(aimlstarter, 'w') as fileo:
|
||||
fileo.write(
|
||||
"<aiml version='1.0.1' encoding='UTF-8'>"
|
||||
" <!-- std-startup.xml -->\n"
|
||||
" <category>\n"
|
||||
" <pattern>LOAD AIML B</pattern>\n"
|
||||
" <template>\n"
|
||||
" <learn>{}</learn>\n"
|
||||
" </template>\n"
|
||||
" </category>\n"
|
||||
"</aiml>".format(os.path.join(aimldir, "*"))
|
||||
)
|
||||
self.aiml_kernel.learn(aimlstarter)
|
||||
self.aiml_kernel.respond("LOAD AIML B")
|
||||
self.save_brain()
|
||||
else:
|
||||
import sopel_modules
|
||||
for plugin_dir in set(sopel_modules.__path__):
|
||||
configsdir = os.path.join(plugin_dir, "SpiceBot_Configs")
|
||||
aimldir = os.path.join(configsdir, "aiml")
|
||||
aimlstarter = tempfile.mkstemp()[1]
|
||||
with open(aimlstarter, 'w') as fileo:
|
||||
fileo.write(
|
||||
"<aiml version='1.0.1' encoding='UTF-8'>"
|
||||
" <!-- std-startup.xml -->\n"
|
||||
" <category>\n"
|
||||
" <pattern>LOAD AIML B</pattern>\n"
|
||||
" <template>\n"
|
||||
" <learn>{}</learn>\n"
|
||||
" </template>\n"
|
||||
" </category>\n"
|
||||
"</aiml>".format(os.path.join(aimldir, "*"))
|
||||
)
|
||||
self.aiml_kernel.learn(aimlstarter)
|
||||
self.aiml_kernel.respond("LOAD AIML B")
|
||||
os.remove(aimlstarter)
|
||||
self.save_brain()
|
||||
|
||||
def save_brain(self):
|
||||
self.aiml_kernel.saveBrain(botconfig.config.aibrain)
|
||||
os.remove(aimlstarter)
|
||||
|
||||
def on_message(self, bot, trigger, message):
|
||||
nick = Identifier(trigger.nick)
|
||||
|
||||
@ -32,8 +32,6 @@ class BotConfig():
|
||||
self.config.core.logs_raw = os.path.join(self.config.core.logdir, 'raw.log')
|
||||
# self.config.core.logs_raw = os.path.os.path.join(self.config.core.logdir, self.config.basename + '.raw.log')
|
||||
|
||||
self.config.aibrain = os.path.join(self.config.homedir, self.config.basename + '.aibrain.brn')
|
||||
|
||||
# load as dict
|
||||
config = configparser.ConfigParser()
|
||||
config.read(self.config.filename)
|
||||
|
||||
@ -55,8 +55,6 @@ def setup(bot):
|
||||
bot.config.core.logs_raw = os.path.join(bot.config.core.logdir, 'raw.log')
|
||||
# bot.config.core.logs_raw = os.path.os.path.join(bot.config.core.logdir, bot.config.basename + '.raw.log')
|
||||
|
||||
bot.config.aibrain = os.path.join(bot.config.homedir, bot.config.basename + '.aibrain.brn')
|
||||
|
||||
logs.log('SpiceBot_Channels', "Setting Up Configuration")
|
||||
events.startup_add([events.BOT_CHANNELS])
|
||||
bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||
|
||||
@ -6,5 +6,4 @@ from .AI import botai
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
botai.save_brain()
|
||||
pass
|
||||
|
||||
Loading…
Reference in New Issue
Block a user