From b1602147ec72800345ce092ab12ee71a7a739931 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 5 Jun 2019 18:21:27 -0400 Subject: [PATCH] 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: