From 576f7ff197ca7987b1a2dc62bcfecf411a57c65d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 17:22:52 -0400 Subject: [PATCH 01/30] encode --- sopel_modules/SpiceBot/AI.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index 850669e..713e1e7 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -232,11 +232,13 @@ class SpiceBot_AI(): nick = Identifier(nick) nick_id = botdb.get_nick_id(nick, create=True) sessionData = self.aiml_kernel.getSessionData(nick_id) + sessionData = {k: unicode(v).encode("utf-8") for k, v in sessionData.iteritems()} botdb.set_nick_value(nick, 'botai', sessionData) def save_brain(self): self.aiml_kernel.saveBrain(botconfig.config.aibrain) botsessiondata = self.aiml_kernel._botPredicates + botsessiondata = {k: unicode(v).encode("utf-8") for k, v in botsessiondata.iteritems()} botdb.set_bot_value('botai', botsessiondata) From 7ad399c1b8c55da12a52f25da98b0f5ebcafc83c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 17:39:53 -0400 Subject: [PATCH 02/30] utf8 --- sopel_modules/SpiceBot/AI.py | 2 -- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index 713e1e7..850669e 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -232,13 +232,11 @@ class SpiceBot_AI(): nick = Identifier(nick) nick_id = botdb.get_nick_id(nick, create=True) sessionData = self.aiml_kernel.getSessionData(nick_id) - sessionData = {k: unicode(v).encode("utf-8") for k, v in sessionData.iteritems()} botdb.set_nick_value(nick, 'botai', sessionData) def save_brain(self): self.aiml_kernel.saveBrain(botconfig.config.aibrain) botsessiondata = self.aiml_kernel._botPredicates - botsessiondata = {k: unicode(v).encode("utf-8") for k, v in botsessiondata.iteritems()} botdb.set_bot_value('botai', botsessiondata) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index cd48826..6df0504 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -59,7 +59,7 @@ def bot_command_rule(bot, trigger): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') fulltrigger = spicemanip.main(trigger_args, 0) - returnmessage = SpiceBot.botai.on_message(bot, trigger, message) + returnmessage = SpiceBot.botai.on_message(bot, trigger, message.decode('utf-8', 'ignore')) if returnmessage: bot.osd(str(returnmessage)) else: From ccc153e059289c0c36a16d95c5c72cd98cbf91fd Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 17:55:44 -0400 Subject: [PATCH 03/30] patch database --- sopel_modules/SpiceBot/Database.py | 53 +++++++++++++++++++++++++++- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 9c07eda..cf27c2d 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -11,11 +11,13 @@ from sopel.db import SopelDB, _deserialize from .Config import config as botconfig -from sqlalchemy import Column, String, ForeignKey, Integer, Text +from sqlalchemy import Column, String, ForeignKey, Integer, Text, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import SQLAlchemyError +from sqlalchemy.engine.url import URL import json +import os BASE = declarative_base() @@ -496,6 +498,55 @@ class BotDatabase(): def __init__(self): + # patch unicode issues + # MySQL - mysql://username:password@localhost/db + # SQLite - sqlite:////home/sopel/.sopel/default.db + db_type = botconfig.config.core.db_type + + # Handle SQLite explicitly as a default + if db_type == 'sqlite': + path = botconfig.config.core.db_filename + config_dir, config_file = os.path.split(botconfig.config.filename) + config_name, _ = os.path.splitext(config_file) + if path is None: + path = os.path.join(config_dir, config_name + '.db') + path = os.path.expanduser(path) + if not os.path.isabs(path): + path = os.path.normpath(os.path.join(config_dir, path)) + self.filename = path + self.url = 'sqlite:///%s' % path + # Otherwise, handle all other database engines + else: + if db_type == 'mysql': + drivername = botconfig.config.core.db_driver or 'mysql' + elif db_type == 'postgres': + drivername = botconfig.config.core.db_driver or 'postgresql' + elif db_type == 'oracle': + drivername = botconfig.config.core.db_driver or 'oracle' + elif db_type == 'mssql': + drivername = botconfig.config.core.db_driver or 'mssql+pymssql' + elif db_type == 'firebird': + drivername = botconfig.config.core.db_driver or 'firebird+fdb' + elif db_type == 'sybase': + drivername = botconfig.config.core.db_driver or 'sybase+pysybase' + else: + raise Exception('Unknown db_type') + + db_user = botconfig.config.core.db_user + db_pass = botconfig.config.core.db_pass + db_host = botconfig.config.core.db_host + db_port = botconfig.config.core.db_port # Optional + db_name = botconfig.config.core.db_name # Optional, depending on DB + + # Ensure we have all our variables defined + if db_user is None or db_pass is None or db_host is None: + raise Exception('Please make sure the following core ' + 'configuration values are defined: ' + 'db_user, db_pass, db_host') + SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, + host=db_host, port=db_port, database=db_name, use_unicode=True, charset="utf8") + SopelDB.engine = create_engine(SopelDB.url) + sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value SopelDB.set_nick_value = SpiceDB.set_nick_value diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 6df0504..cd48826 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -59,7 +59,7 @@ def bot_command_rule(bot, trigger): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') fulltrigger = spicemanip.main(trigger_args, 0) - returnmessage = SpiceBot.botai.on_message(bot, trigger, message.decode('utf-8', 'ignore')) + returnmessage = SpiceBot.botai.on_message(bot, trigger, message) if returnmessage: bot.osd(str(returnmessage)) else: From 00205677e92f354ddc186be6681bb4afe8c6e170 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 17:59:16 -0400 Subject: [PATCH 04/30] patch for no reason --- sopel_modules/SpiceBot/Database.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index cf27c2d..03d4192 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -513,8 +513,8 @@ class BotDatabase(): path = os.path.expanduser(path) if not os.path.isabs(path): path = os.path.normpath(os.path.join(config_dir, path)) - self.filename = path - self.url = 'sqlite:///%s' % path + SopelDB.filename = path + SopelDB.url = 'sqlite:///%s' % path # Otherwise, handle all other database engines else: if db_type == 'mysql': From 7d425d529dddfe1932defadff2d837f7e3e3ad4a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:00:35 -0400 Subject: [PATCH 05/30] test --- sopel_modules/SpiceBot/Database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 03d4192..59accc8 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -544,7 +544,7 @@ class BotDatabase(): 'configuration values are defined: ' 'db_user, db_pass, db_host') SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, - host=db_host, port=db_port, database=db_name, use_unicode=True, charset="utf8") + host=db_host, port=db_port, database=db_name, charset="utf8") SopelDB.engine = create_engine(SopelDB.url) sopel.db.NickValues = NickValues From 6dd0d08da2b02129811547a66572fe9aba68e9f2 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:03:22 -0400 Subject: [PATCH 06/30] test --- sopel_modules/SpiceBot/Database.py | 55 ++---------------------------- 1 file changed, 3 insertions(+), 52 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 59accc8..d37a6c3 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -49,7 +49,7 @@ class NickValues(BASE): nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text()) + value = Column(Text(), convert_unicode=True) class ChannelValues(BASE): @@ -60,7 +60,7 @@ class ChannelValues(BASE): channel = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text()) + value = Column(Text(), convert_unicode=True) class PluginValues(BASE): @@ -71,7 +71,7 @@ class PluginValues(BASE): plugin = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text()) + value = Column(Text(), convert_unicode=True) class SpiceDB(object): @@ -498,55 +498,6 @@ class BotDatabase(): def __init__(self): - # patch unicode issues - # MySQL - mysql://username:password@localhost/db - # SQLite - sqlite:////home/sopel/.sopel/default.db - db_type = botconfig.config.core.db_type - - # Handle SQLite explicitly as a default - if db_type == 'sqlite': - path = botconfig.config.core.db_filename - config_dir, config_file = os.path.split(botconfig.config.filename) - config_name, _ = os.path.splitext(config_file) - if path is None: - path = os.path.join(config_dir, config_name + '.db') - path = os.path.expanduser(path) - if not os.path.isabs(path): - path = os.path.normpath(os.path.join(config_dir, path)) - SopelDB.filename = path - SopelDB.url = 'sqlite:///%s' % path - # Otherwise, handle all other database engines - else: - if db_type == 'mysql': - drivername = botconfig.config.core.db_driver or 'mysql' - elif db_type == 'postgres': - drivername = botconfig.config.core.db_driver or 'postgresql' - elif db_type == 'oracle': - drivername = botconfig.config.core.db_driver or 'oracle' - elif db_type == 'mssql': - drivername = botconfig.config.core.db_driver or 'mssql+pymssql' - elif db_type == 'firebird': - drivername = botconfig.config.core.db_driver or 'firebird+fdb' - elif db_type == 'sybase': - drivername = botconfig.config.core.db_driver or 'sybase+pysybase' - else: - raise Exception('Unknown db_type') - - db_user = botconfig.config.core.db_user - db_pass = botconfig.config.core.db_pass - db_host = botconfig.config.core.db_host - db_port = botconfig.config.core.db_port # Optional - db_name = botconfig.config.core.db_name # Optional, depending on DB - - # Ensure we have all our variables defined - if db_user is None or db_pass is None or db_host is None: - raise Exception('Please make sure the following core ' - 'configuration values are defined: ' - 'db_user, db_pass, db_host') - SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, - host=db_host, port=db_port, database=db_name, charset="utf8") - SopelDB.engine = create_engine(SopelDB.url) - sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value SopelDB.set_nick_value = SpiceDB.set_nick_value From d81e563922c12fe5dd1cd07e9a24d6e03308111f Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:04:04 -0400 Subject: [PATCH 07/30] remove imports --- sopel_modules/SpiceBot/Database.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index d37a6c3..a6959e6 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -11,13 +11,11 @@ from sopel.db import SopelDB, _deserialize from .Config import config as botconfig -from sqlalchemy import Column, String, ForeignKey, Integer, Text, create_engine +from sqlalchemy import Column, String, ForeignKey, Integer, Text from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import SQLAlchemyError -from sqlalchemy.engine.url import URL import json -import os BASE = declarative_base() From d1436de6cc4ad040e42ec228a7a6449f64ce4aa1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:07:58 -0400 Subject: [PATCH 08/30] try --- sopel_modules/SpiceBot/Database.py | 53 +++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index a6959e6..8b9e176 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -11,11 +11,13 @@ from sopel.db import SopelDB, _deserialize from .Config import config as botconfig -from sqlalchemy import Column, String, ForeignKey, Integer, Text +from sqlalchemy import Column, String, ForeignKey, Integer, Text, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import SQLAlchemyError +from sqlalchemy.engine.url import URL import json +import os BASE = declarative_base() @@ -496,6 +498,55 @@ class BotDatabase(): def __init__(self): + # patch unicode issues + # MySQL - mysql://username:password@localhost/db + # SQLite - sqlite:////home/sopel/.sopel/default.db + db_type = botconfig.config.core.db_type + + # Handle SQLite explicitly as a default + if db_type == 'sqlite': + path = botconfig.config.core.db_filename + config_dir, config_file = os.path.split(botconfig.config.filename) + config_name, _ = os.path.splitext(config_file) + if path is None: + path = os.path.join(config_dir, config_name + '.db') + path = os.path.expanduser(path) + if not os.path.isabs(path): + path = os.path.normpath(os.path.join(config_dir, path)) + SopelDB.filename = path + SopelDB.url = 'sqlite:///%s' % path + # Otherwise, handle all other database engines + else: + if db_type == 'mysql': + drivername = botconfig.config.core.db_driver or 'mysql' + elif db_type == 'postgres': + drivername = botconfig.config.core.db_driver or 'postgresql' + elif db_type == 'oracle': + drivername = botconfig.config.core.db_driver or 'oracle' + elif db_type == 'mssql': + drivername = botconfig.config.core.db_driver or 'mssql+pymssql' + elif db_type == 'firebird': + drivername = botconfig.config.core.db_driver or 'firebird+fdb' + elif db_type == 'sybase': + drivername = botconfig.config.core.db_driver or 'sybase+pysybase' + else: + raise Exception('Unknown db_type') + + db_user = botconfig.config.core.db_user + db_pass = botconfig.config.core.db_pass + db_host = botconfig.config.core.db_host + db_port = botconfig.config.core.db_port # Optional + db_name = botconfig.config.core.db_name # Optional, depending on DB + + # Ensure we have all our variables defined + if db_user is None or db_pass is None or db_host is None: + raise Exception('Please make sure the following core ' + 'configuration values are defined: ' + 'db_user, db_pass, db_host') + SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, + host=db_host, port=db_port, database=db_name, query={'charset': 'utf8'}) + SopelDB.engine = create_engine(SopelDB.url, encoding='utf-8') + sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value SopelDB.set_nick_value = SpiceDB.set_nick_value From ab80a4a0420d4e442b0fb91b1eff7a843d036ba9 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:10:03 -0400 Subject: [PATCH 09/30] test --- sopel_modules/SpiceBot/Database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 8b9e176..651749d 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -545,7 +545,7 @@ class BotDatabase(): 'db_user, db_pass, db_host') SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, host=db_host, port=db_port, database=db_name, query={'charset': 'utf8'}) - SopelDB.engine = create_engine(SopelDB.url, encoding='utf-8') + SopelDB.engine = create_engine(SopelDB.url, encoding='utf-8', convert_unicode=True) sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value From 2b8a8ac309321f4b477c6d9b5348913642ff9787 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:15:59 -0400 Subject: [PATCH 10/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index cd48826..53f52b9 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -59,7 +59,7 @@ def bot_command_rule(bot, trigger): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') fulltrigger = spicemanip.main(trigger_args, 0) - returnmessage = SpiceBot.botai.on_message(bot, trigger, message) + returnmessage = SpiceBot.botai.on_message(bot, trigger, message.encode('utf-8')) if returnmessage: bot.osd(str(returnmessage)) else: From b1602147ec72800345ce092ab12ee71a7a739931 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:21:27 -0400 Subject: [PATCH 11/30] test --- sopel_modules/SpiceBot/Database.py | 59 ++-------------------------- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 2 files changed, 5 insertions(+), 56 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 651749d..9c07eda 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -11,13 +11,11 @@ from sopel.db import SopelDB, _deserialize from .Config import config as botconfig -from sqlalchemy import Column, String, ForeignKey, Integer, Text, create_engine +from sqlalchemy import Column, String, ForeignKey, Integer, Text from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import SQLAlchemyError -from sqlalchemy.engine.url import URL import json -import os BASE = declarative_base() @@ -49,7 +47,7 @@ class NickValues(BASE): nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text(), convert_unicode=True) + value = Column(Text()) class ChannelValues(BASE): @@ -60,7 +58,7 @@ class ChannelValues(BASE): channel = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text(), convert_unicode=True) + value = Column(Text()) class PluginValues(BASE): @@ -71,7 +69,7 @@ class PluginValues(BASE): plugin = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text(), convert_unicode=True) + value = Column(Text()) class SpiceDB(object): @@ -498,55 +496,6 @@ class BotDatabase(): def __init__(self): - # patch unicode issues - # MySQL - mysql://username:password@localhost/db - # SQLite - sqlite:////home/sopel/.sopel/default.db - db_type = botconfig.config.core.db_type - - # Handle SQLite explicitly as a default - if db_type == 'sqlite': - path = botconfig.config.core.db_filename - config_dir, config_file = os.path.split(botconfig.config.filename) - config_name, _ = os.path.splitext(config_file) - if path is None: - path = os.path.join(config_dir, config_name + '.db') - path = os.path.expanduser(path) - if not os.path.isabs(path): - path = os.path.normpath(os.path.join(config_dir, path)) - SopelDB.filename = path - SopelDB.url = 'sqlite:///%s' % path - # Otherwise, handle all other database engines - else: - if db_type == 'mysql': - drivername = botconfig.config.core.db_driver or 'mysql' - elif db_type == 'postgres': - drivername = botconfig.config.core.db_driver or 'postgresql' - elif db_type == 'oracle': - drivername = botconfig.config.core.db_driver or 'oracle' - elif db_type == 'mssql': - drivername = botconfig.config.core.db_driver or 'mssql+pymssql' - elif db_type == 'firebird': - drivername = botconfig.config.core.db_driver or 'firebird+fdb' - elif db_type == 'sybase': - drivername = botconfig.config.core.db_driver or 'sybase+pysybase' - else: - raise Exception('Unknown db_type') - - db_user = botconfig.config.core.db_user - db_pass = botconfig.config.core.db_pass - db_host = botconfig.config.core.db_host - db_port = botconfig.config.core.db_port # Optional - db_name = botconfig.config.core.db_name # Optional, depending on DB - - # Ensure we have all our variables defined - if db_user is None or db_pass is None or db_host is None: - raise Exception('Please make sure the following core ' - 'configuration values are defined: ' - 'db_user, db_pass, db_host') - SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, - host=db_host, port=db_port, database=db_name, query={'charset': 'utf8'}) - SopelDB.engine = create_engine(SopelDB.url, encoding='utf-8', convert_unicode=True) - sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value SopelDB.set_nick_value = SpiceDB.set_nick_value diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 53f52b9..81cff2e 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -59,7 +59,7 @@ def bot_command_rule(bot, trigger): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') fulltrigger = spicemanip.main(trigger_args, 0) - returnmessage = SpiceBot.botai.on_message(bot, trigger, message.encode('utf-8')) + returnmessage = SpiceBot.botai.on_message(bot, trigger, str(message).encode('utf-8')) if returnmessage: bot.osd(str(returnmessage)) else: From 3ca472bf51731ce3b64c25820cfc0fd77b686cbb Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:28:12 -0400 Subject: [PATCH 12/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 81cff2e..7db20d4 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -23,6 +23,9 @@ def bot_command_rule(bot, trigger): message = trigger.args[1] + if is_ascii(message): + return + # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') @@ -59,7 +62,7 @@ def bot_command_rule(bot, trigger): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') fulltrigger = spicemanip.main(trigger_args, 0) - returnmessage = SpiceBot.botai.on_message(bot, trigger, str(message).encode('utf-8')) + returnmessage = SpiceBot.botai.on_message(bot, trigger, message) if returnmessage: bot.osd(str(returnmessage)) else: @@ -86,3 +89,7 @@ def bot_command_rule(bot, trigger): else: bot.osd("I don't know what you are asking me to do!") return + + +def is_ascii(s): + return all(ord(c) < 128 for c in s) From b95b41e9abbe27522ab689d2452067b71d1ccae7 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:35:22 -0400 Subject: [PATCH 13/30] test --- sopel_modules/SpiceBot/AI.py | 25 +++++++++++++++---------- sopel_modules/SpiceBot_AI/AI_aiml.py | 5 +---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index 850669e..9ba7b56 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -121,20 +121,25 @@ class SpiceBot_AI(): self.aiml_kernel.respond("LOAD AIML B") def on_message(self, bot, trigger, message): + try: - nick = Identifier(trigger.nick) - nick_id = botdb.get_nick_id(nick, create=True) - self.check_user_import(nick, nick_id) + nick = Identifier(trigger.nick) + nick_id = botdb.get_nick_id(nick, create=True) + self.check_user_import(nick, nick_id) - message = self.bot_message_precipher(bot, trigger, message) - aiml_response = self.aiml_kernel.respond(message, nick_id) - if aiml_response: - aiml_response = self.bot_message_decipher(bot, trigger, aiml_response) + message = self.bot_message_precipher(bot, trigger, message) + aiml_response = self.aiml_kernel.respond(message, nick_id) + if aiml_response: + aiml_response = self.bot_message_decipher(bot, trigger, aiml_response) - self.save_nick_session(nick, nick_id) - self.save_brain() + self.save_nick_session(nick, nick_id) + self.save_brain() - return aiml_response + return aiml_response + except Exception as e: + returnval = e + returnval = None + return returnval def bot_message_precipher(self, bot, trigger, message): diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 7db20d4..76b4892 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -23,9 +23,6 @@ def bot_command_rule(bot, trigger): message = trigger.args[1] - if is_ascii(message): - return - # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') @@ -62,7 +59,7 @@ def bot_command_rule(bot, trigger): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') fulltrigger = spicemanip.main(trigger_args, 0) - returnmessage = SpiceBot.botai.on_message(bot, trigger, message) + returnmessage = SpiceBot.botai.on_message(bot, trigger, str(message).encode('utf-8')) if returnmessage: bot.osd(str(returnmessage)) else: From e4ff6d30db2d5fc6dc95c75479ba440758aaabb6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:39:21 -0400 Subject: [PATCH 14/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 76b4892..278b96d 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -23,6 +23,9 @@ def bot_command_rule(bot, trigger): message = trigger.args[1] + if is_ascii(message): + return + # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') From 1a2caf079e46083cdb8142efe88561ee64e8442c Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:43:15 -0400 Subject: [PATCH 15/30] test --- sopel_modules/SpiceBot/AI.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index 9ba7b56..a25f6da 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -121,25 +121,19 @@ class SpiceBot_AI(): self.aiml_kernel.respond("LOAD AIML B") def on_message(self, bot, trigger, message): - try: + nick = Identifier(trigger.nick) + nick_id = botdb.get_nick_id(nick, create=True) + self.check_user_import(nick, nick_id) - nick = Identifier(trigger.nick) - nick_id = botdb.get_nick_id(nick, create=True) - self.check_user_import(nick, nick_id) + message = self.bot_message_precipher(bot, trigger, message) + aiml_response = self.aiml_kernel.respond(message, nick_id) + if aiml_response: + aiml_response = self.bot_message_decipher(bot, trigger, aiml_response) - message = self.bot_message_precipher(bot, trigger, message) - aiml_response = self.aiml_kernel.respond(message, nick_id) - if aiml_response: - aiml_response = self.bot_message_decipher(bot, trigger, aiml_response) + self.save_nick_session(nick, nick_id) + self.save_brain() - self.save_nick_session(nick, nick_id) - self.save_brain() - - return aiml_response - except Exception as e: - returnval = e - returnval = None - return returnval + return aiml_response def bot_message_precipher(self, bot, trigger, message): From d59767fa0f067d4fcdf220a28d362e1fe3a88f66 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:51:58 -0400 Subject: [PATCH 16/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 278b96d..d40de6a 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = trigger.args[1] + message = str(trigger.args[1]).encode('utf-8', 'replace') if is_ascii(message): return @@ -62,7 +62,7 @@ def bot_command_rule(bot, trigger): trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') fulltrigger = spicemanip.main(trigger_args, 0) - returnmessage = SpiceBot.botai.on_message(bot, trigger, str(message).encode('utf-8')) + returnmessage = SpiceBot.botai.on_message(bot, trigger, message) if returnmessage: bot.osd(str(returnmessage)) else: @@ -92,4 +92,9 @@ def bot_command_rule(bot, trigger): def is_ascii(s): - return all(ord(c) < 128 for c in s) + try: + s.decode('ascii') + except UnicodeDecodeError: + return False + else: + return True From c1ea074761f763fa941ec0f54ce9ceb15f980d10 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:55:17 -0400 Subject: [PATCH 17/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index d40de6a..1212999 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,10 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = str(trigger.args[1]).encode('utf-8', 'replace') - - if is_ascii(message): - return + message = str(trigger.args[1]).decode('utf-8') # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): @@ -89,12 +86,3 @@ def bot_command_rule(bot, trigger): else: bot.osd("I don't know what you are asking me to do!") return - - -def is_ascii(s): - try: - s.decode('ascii') - except UnicodeDecodeError: - return False - else: - return True From a2f8a84a314ab3ab8c4650876360b7f251fdd61d Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:00:47 -0400 Subject: [PATCH 18/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 1212999..8f9bf74 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = str(trigger.args[1]).decode('utf-8') + message = str(trigger.args[1]).encode('utf-8').decode('utf-8') # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): From ea4d4ee6dd8d036412396328b1b2feeffa420ef0 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:08:50 -0400 Subject: [PATCH 19/30] test --- sopel_modules/SpiceBot/Database.py | 59 ++++++++++++++++++++++++++-- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 9c07eda..651749d 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -11,11 +11,13 @@ from sopel.db import SopelDB, _deserialize from .Config import config as botconfig -from sqlalchemy import Column, String, ForeignKey, Integer, Text +from sqlalchemy import Column, String, ForeignKey, Integer, Text, create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import SQLAlchemyError +from sqlalchemy.engine.url import URL import json +import os BASE = declarative_base() @@ -47,7 +49,7 @@ class NickValues(BASE): nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text()) + value = Column(Text(), convert_unicode=True) class ChannelValues(BASE): @@ -58,7 +60,7 @@ class ChannelValues(BASE): channel = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text()) + value = Column(Text(), convert_unicode=True) class PluginValues(BASE): @@ -69,7 +71,7 @@ class PluginValues(BASE): plugin = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text()) + value = Column(Text(), convert_unicode=True) class SpiceDB(object): @@ -496,6 +498,55 @@ class BotDatabase(): def __init__(self): + # patch unicode issues + # MySQL - mysql://username:password@localhost/db + # SQLite - sqlite:////home/sopel/.sopel/default.db + db_type = botconfig.config.core.db_type + + # Handle SQLite explicitly as a default + if db_type == 'sqlite': + path = botconfig.config.core.db_filename + config_dir, config_file = os.path.split(botconfig.config.filename) + config_name, _ = os.path.splitext(config_file) + if path is None: + path = os.path.join(config_dir, config_name + '.db') + path = os.path.expanduser(path) + if not os.path.isabs(path): + path = os.path.normpath(os.path.join(config_dir, path)) + SopelDB.filename = path + SopelDB.url = 'sqlite:///%s' % path + # Otherwise, handle all other database engines + else: + if db_type == 'mysql': + drivername = botconfig.config.core.db_driver or 'mysql' + elif db_type == 'postgres': + drivername = botconfig.config.core.db_driver or 'postgresql' + elif db_type == 'oracle': + drivername = botconfig.config.core.db_driver or 'oracle' + elif db_type == 'mssql': + drivername = botconfig.config.core.db_driver or 'mssql+pymssql' + elif db_type == 'firebird': + drivername = botconfig.config.core.db_driver or 'firebird+fdb' + elif db_type == 'sybase': + drivername = botconfig.config.core.db_driver or 'sybase+pysybase' + else: + raise Exception('Unknown db_type') + + db_user = botconfig.config.core.db_user + db_pass = botconfig.config.core.db_pass + db_host = botconfig.config.core.db_host + db_port = botconfig.config.core.db_port # Optional + db_name = botconfig.config.core.db_name # Optional, depending on DB + + # Ensure we have all our variables defined + if db_user is None or db_pass is None or db_host is None: + raise Exception('Please make sure the following core ' + 'configuration values are defined: ' + 'db_user, db_pass, db_host') + SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, + host=db_host, port=db_port, database=db_name, query={'charset': 'utf8'}) + SopelDB.engine = create_engine(SopelDB.url, encoding='utf-8', convert_unicode=True) + sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value SopelDB.set_nick_value = SpiceDB.set_nick_value diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 8f9bf74..2a94236 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = str(trigger.args[1]).encode('utf-8').decode('utf-8') + message = str(trigger.args[1], 'utf-8') # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): From 36feee99bc41a226de5e3f3c36396544a2faf1df Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:13:14 -0400 Subject: [PATCH 20/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 2a94236..bc80326 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = str(trigger.args[1], 'utf-8') + message = str(trigger.args[1]).encode('utf-8', 'replace') # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): From 8e5e8a734a7bffd7c83b1448458a2cefda0b33e6 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:16:41 -0400 Subject: [PATCH 21/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index bc80326..cd48826 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = str(trigger.args[1]).encode('utf-8', 'replace') + message = trigger.args[1] # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): From 6048f779f13fe146c9ede769d00142352259178b Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:20:09 -0400 Subject: [PATCH 22/30] revert --- sopel_modules/SpiceBot/Database.py | 59 ++---------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/sopel_modules/SpiceBot/Database.py b/sopel_modules/SpiceBot/Database.py index 651749d..9c07eda 100644 --- a/sopel_modules/SpiceBot/Database.py +++ b/sopel_modules/SpiceBot/Database.py @@ -11,13 +11,11 @@ from sopel.db import SopelDB, _deserialize from .Config import config as botconfig -from sqlalchemy import Column, String, ForeignKey, Integer, Text, create_engine +from sqlalchemy import Column, String, ForeignKey, Integer, Text from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.exc import SQLAlchemyError -from sqlalchemy.engine.url import URL import json -import os BASE = declarative_base() @@ -49,7 +47,7 @@ class NickValues(BASE): nick_id = Column(Integer, ForeignKey('nick_ids.nick_id'), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text(), convert_unicode=True) + value = Column(Text()) class ChannelValues(BASE): @@ -60,7 +58,7 @@ class ChannelValues(BASE): channel = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text(), convert_unicode=True) + value = Column(Text()) class PluginValues(BASE): @@ -71,7 +69,7 @@ class PluginValues(BASE): plugin = Column(String(255), primary_key=True) namespace = Column(String(255), primary_key=True) key = Column(String(255), primary_key=True) - value = Column(Text(), convert_unicode=True) + value = Column(Text()) class SpiceDB(object): @@ -498,55 +496,6 @@ class BotDatabase(): def __init__(self): - # patch unicode issues - # MySQL - mysql://username:password@localhost/db - # SQLite - sqlite:////home/sopel/.sopel/default.db - db_type = botconfig.config.core.db_type - - # Handle SQLite explicitly as a default - if db_type == 'sqlite': - path = botconfig.config.core.db_filename - config_dir, config_file = os.path.split(botconfig.config.filename) - config_name, _ = os.path.splitext(config_file) - if path is None: - path = os.path.join(config_dir, config_name + '.db') - path = os.path.expanduser(path) - if not os.path.isabs(path): - path = os.path.normpath(os.path.join(config_dir, path)) - SopelDB.filename = path - SopelDB.url = 'sqlite:///%s' % path - # Otherwise, handle all other database engines - else: - if db_type == 'mysql': - drivername = botconfig.config.core.db_driver or 'mysql' - elif db_type == 'postgres': - drivername = botconfig.config.core.db_driver or 'postgresql' - elif db_type == 'oracle': - drivername = botconfig.config.core.db_driver or 'oracle' - elif db_type == 'mssql': - drivername = botconfig.config.core.db_driver or 'mssql+pymssql' - elif db_type == 'firebird': - drivername = botconfig.config.core.db_driver or 'firebird+fdb' - elif db_type == 'sybase': - drivername = botconfig.config.core.db_driver or 'sybase+pysybase' - else: - raise Exception('Unknown db_type') - - db_user = botconfig.config.core.db_user - db_pass = botconfig.config.core.db_pass - db_host = botconfig.config.core.db_host - db_port = botconfig.config.core.db_port # Optional - db_name = botconfig.config.core.db_name # Optional, depending on DB - - # Ensure we have all our variables defined - if db_user is None or db_pass is None or db_host is None: - raise Exception('Please make sure the following core ' - 'configuration values are defined: ' - 'db_user, db_pass, db_host') - SopelDB.url = URL(drivername=drivername, username=db_user, password=db_pass, - host=db_host, port=db_port, database=db_name, query={'charset': 'utf8'}) - SopelDB.engine = create_engine(SopelDB.url, encoding='utf-8', convert_unicode=True) - sopel.db.NickValues = NickValues SopelDB.get_nick_value = SpiceDB.get_nick_value SopelDB.set_nick_value = SpiceDB.set_nick_value From 581c4b99c3c0f4cf13f21665e79cca7d4501f147 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:36:06 -0400 Subject: [PATCH 23/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index cd48826..293dca6 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = trigger.args[1] + message = trigger.args[1].encode('ascii','ignore') # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): From 4758db43bedf92320181d8d4d620cf3b3671e794 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:36:15 -0400 Subject: [PATCH 24/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 293dca6..2035902 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = trigger.args[1].encode('ascii','ignore') + message = trigger.args[1].encode('ascii', 'ignore') # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): From abef636c158d73369273eef10bb64ccc499fb4d3 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:40:30 -0400 Subject: [PATCH 25/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 2035902..03f089b 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,7 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = trigger.args[1].encode('ascii', 'ignore') + message = str(trigger.args[1]) # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): From d33178d87c5bd3eaa4c62d932e754df056e56abf Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:48:46 -0400 Subject: [PATCH 26/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 03f089b..a9c3679 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -21,7 +21,8 @@ def bot_command_rule(bot, trigger): if not len(trigger.args): return - message = str(trigger.args[1]) + message = trigger.args[1] + message = return_utf(message) # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): @@ -86,3 +87,20 @@ def bot_command_rule(bot, trigger): else: bot.osd("I don't know what you are asking me to do!") return + + +def return_utf(s): + if isinstance(s, str): + return s.encode('utf-8') + if isinstance(s, (int, float, complex)): + return str(s).encode('utf-8') + try: + return s.encode('utf-8') + except TypeError: + try: + return str(s).encode('utf-8') + except AttributeError: + return s + except AttributeError: + return s + return s # assume it was already utf-8 From cb0b0dce45c2a0e6e7d9b61286a7fb930eb9a27a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 19:50:53 -0400 Subject: [PATCH 27/30] test without bot db --- sopel_modules/SpiceBot/AI.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sopel_modules/SpiceBot/AI.py b/sopel_modules/SpiceBot/AI.py index a25f6da..23d3919 100644 --- a/sopel_modules/SpiceBot/AI.py +++ b/sopel_modules/SpiceBot/AI.py @@ -74,11 +74,11 @@ class SpiceBot_AI(): def load_bot_values(self): - current_bot_db = botdb.get_bot_value('botai') or None - if current_bot_db: - for predicate in current_bot_db.keys(): - predval = current_bot_db[predicate] - self.aiml_kernel.setBotPredicate(predicate, predval) + # current_bot_db = botdb.get_bot_value('botai') or None + # if current_bot_db: + # for predicate in current_bot_db.keys(): + # predval = current_bot_db[predicate] + # self.aiml_kernel.setBotPredicate(predicate, predval) # sopel nick self.aiml_kernel.setBotPredicate("nick", botconfig.nick) @@ -235,8 +235,8 @@ class SpiceBot_AI(): def save_brain(self): self.aiml_kernel.saveBrain(botconfig.config.aibrain) - botsessiondata = self.aiml_kernel._botPredicates - botdb.set_bot_value('botai', botsessiondata) + # botsessiondata = self.aiml_kernel._botPredicates + # botdb.set_bot_value('botai', botsessiondata) botai = SpiceBot_AI() From a97afcd9ffcc150516a6d706f92142bc5c91e0f1 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 20:01:04 -0400 Subject: [PATCH 28/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index a9c3679..6427b2d 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -22,7 +22,8 @@ def bot_command_rule(bot, trigger): return message = trigger.args[1] - message = return_utf(message) + if isinstance(message, unicode): + return # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)): @@ -87,20 +88,3 @@ def bot_command_rule(bot, trigger): else: bot.osd("I don't know what you are asking me to do!") return - - -def return_utf(s): - if isinstance(s, str): - return s.encode('utf-8') - if isinstance(s, (int, float, complex)): - return str(s).encode('utf-8') - try: - return s.encode('utf-8') - except TypeError: - try: - return str(s).encode('utf-8') - except AttributeError: - return s - except AttributeError: - return s - return s # assume it was already utf-8 From badb47eb8638dae562ffe6134c34bcf3d22f4408 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 20:04:16 -0400 Subject: [PATCH 29/30] grr --- sopel_modules/SpiceBot_AI/AI_aiml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 6427b2d..2631150 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -22,7 +22,7 @@ def bot_command_rule(bot, trigger): return message = trigger.args[1] - if isinstance(message, unicode): + if isinstance(message, 'unicode'): return # ignore text coming from a valid prefix From 0ce5571c946b620c71bb20510b48deee29afe57a Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 20:28:10 -0400 Subject: [PATCH 30/30] test --- sopel_modules/SpiceBot_AI/AI_aiml.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sopel_modules/SpiceBot_AI/AI_aiml.py b/sopel_modules/SpiceBot_AI/AI_aiml.py index 2631150..c164ae4 100644 --- a/sopel_modules/SpiceBot_AI/AI_aiml.py +++ b/sopel_modules/SpiceBot_AI/AI_aiml.py @@ -22,8 +22,7 @@ def bot_command_rule(bot, trigger): return message = trigger.args[1] - if isinstance(message, 'unicode'): - return + message = ''.join([x for x in message if ord(x) < 128]) # ignore text coming from a valid prefix if str(message).startswith(tuple(bot.config.core.prefix_list)):