Merge pull request #92 from deathbybandaid/development

Development
This commit is contained in:
Deathbybandaid 2019-07-03 09:49:41 -04:00 committed by GitHub
commit 33e00a4f79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 71 additions and 67 deletions

View File

@ -11,14 +11,12 @@ from sopel.db import SopelDB, _deserialize
from .Config import config as botconfig
from sqlalchemy.engine.url import URL
from sqlalchemy import create_engine, Column, String, ForeignKey, Integer, Text
from sqlalchemy import Column, String, ForeignKey, Integer, Text
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.exc import SQLAlchemyError
import json
import threading
import os
BASE = declarative_base()
@ -37,6 +35,7 @@ class Nicknames(BASE):
Nicknames SQLAlchemy Class
"""
__tablename__ = 'spice_nicknames'
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4', 'mysql_collate': 'utf8mb4_unicode_ci'}
nick_id = Column(Integer, ForeignKey('spice_nick_ids.nick_id'), primary_key=True)
slug = Column(String(255), primary_key=True)
canonical = Column(String(255))
@ -47,6 +46,7 @@ class NickValues(BASE):
NickValues SQLAlchemy Class
"""
__tablename__ = 'spice_nick_values'
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4', 'mysql_collate': 'utf8mb4_unicode_ci'}
nick_id = Column(Integer, ForeignKey('spice_nick_ids.nick_id'), primary_key=True)
namespace = Column(String(255), primary_key=True)
key = Column(String(255), primary_key=True)
@ -58,6 +58,7 @@ class ChannelValues(BASE):
ChannelValues SQLAlchemy Class
"""
__tablename__ = 'spice_channel_values'
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4', 'mysql_collate': 'utf8mb4_unicode_ci'}
channel = Column(String(255), primary_key=True)
namespace = Column(String(255), primary_key=True)
key = Column(String(255), primary_key=True)
@ -69,6 +70,7 @@ class PluginValues(BASE):
PluginValues SQLAlchemy Class
"""
__tablename__ = 'spice_plugin_values'
__table_args__ = {'mysql_engine': 'InnoDB', 'mysql_charset': 'utf8mb4', 'mysql_collate': 'utf8mb4_unicode_ci'}
plugin = Column(String(255), primary_key=True)
namespace = Column(String(255), primary_key=True)
key = Column(String(255), primary_key=True)
@ -533,48 +535,6 @@ class BotDatabase():
def __init__(self):
db_type = botconfig.core.db_type
if db_type == 'sqlite':
path = botconfig.core.db_filename
config_dir, config_file = os.path.split(botconfig.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.core.db_driver or 'mysql'
elif db_type == 'postgres':
drivername = botconfig.core.db_driver or 'postgresql'
elif db_type == 'oracle':
drivername = botconfig.core.db_driver or 'oracle'
elif db_type == 'mssql':
drivername = botconfig.core.db_driver or 'mssql+pymssql'
elif db_type == 'firebird':
drivername = botconfig.core.db_driver or 'firebird+fdb'
elif db_type == 'sybase':
drivername = botconfig.core.db_driver or 'sybase+pysybase'
else:
raise Exception('Unknown db_type')
db_user = botconfig.core.db_user
db_pass = botconfig.core.db_pass
db_host = botconfig.core.db_host
db_port = botconfig.core.db_port # Optional
db_name = botconfig.core.db_name # Optional, depending on DB
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.nick_id_lock = threading.Lock()
sopel.db.NickIDs = NickIDs

View File

@ -19,6 +19,7 @@ from .Channels import channels as botchannels
from .MessageLog import messagelog as botmessagelog
from .Config import config as botconfig
from .Users import users as botusers
from .Events import events as botevents
def prerun(t_command_type='module', t_command_subtype=None):
@ -28,6 +29,14 @@ def prerun(t_command_type='module', t_command_subtype=None):
@functools.wraps(function)
def internal_prerun(bot, trigger, *args, **kwargs):
# verify the bot is at a loaded state
while not botevents.check(botevents.BOT_LOADED):
pass
# Verify channel and user exist
verify_channel(trigger)
verify_user(trigger)
botcom = class_create('botcom')
if t_command_type == "nickname":
@ -167,6 +176,29 @@ def prerun_query(t_command_type='module', t_command_subtype=None):
return actual_decorator
def verify_user(trigger):
# Identify
nick_id = botusers.whois_ident(trigger.nick)
# Verify nick is in the all list
botusers.add_to_all(trigger.nick, nick_id)
# Verify nick is in the all list
botusers.add_to_current(trigger.nick, nick_id)
# set current nick
botusers.mark_current_nick(trigger.nick, nick_id)
# add joined channel to nick list
botusers.add_channel(trigger.sender, nick_id)
# mark user as online
botusers.mark_user_online(nick_id)
def verify_channel(trigger):
botchannels.add_channel(trigger.sender)
# Identify
nick_id = botchannels.whois_ident(trigger.nick)
# Verify nick is in the channel list
botchannels.add_to_channel(trigger.sender, trigger.nick, nick_id)
def make_trigger_args(triggerargs_one, trigger_command_type='module'):
trigger_args = spicemanip.main(triggerargs_one, 'create')
if trigger_command_type in ['nickname']:

View File

@ -19,6 +19,7 @@ import re
class BotUsers():
def __init__(self):
self.who_reqs = {}
self.lock = threading.Lock()
# TODO AWAY
self.dict = {

View File

@ -5,6 +5,7 @@ These are the core SpiceBot Classes
This module contains references only for other modules to utilize.
"""
# pylama:ignore=W0401,W0611
from .Config import *
from .Logs import *

View File

@ -9,7 +9,7 @@ import os
from .Config import config as botconfig
from .Logs import logs
from .Events import events
from .Events import events as botevents
from .Channels import SpiceBot_Channels_MainSection
from .Commands import SpiceBot_Commands_MainSection
@ -73,19 +73,19 @@ def setup_config(bot):
def setup_logs(bot):
logs.log('SpiceBot_Logs', "Starting Setup Procedure")
events.startup_add([events.BOT_LOGS])
botevents.startup_add([botevents.BOT_LOGS])
bot.config.core.logs_stdio = os.path.join(bot.config.core.logdir, 'stdio.log')
# bot.config.core.logs_stdio = os.path.os.path.join(bot.config.core.logdir, bot.config.core.basename + '.stdio.log')
bot.config.core.logs_exceptions = os.path.join(bot.config.core.logdir, 'exceptions.log')
# bot.config.core.logs_exceptions = os.path.os.path.join(bot.config.core.logdir, bot.config.core.basename + '.exceptions.log')
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.core.basename + '.raw.log')
events.trigger(bot, events.BOT_LOGS, "SpiceBot_Logs")
botevents.trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs")
def setup_commands(bot):
logs.log('SpiceBot_Commands', "Setting Up Configuration")
events.startup_add([events.BOT_COMMANDS])
botevents.startup_add([botevents.BOT_COMMANDS])
bot.config.define_section("SpiceBot_Commands", SpiceBot_Commands_MainSection, validate=False)
bot.config.core.query_list = str(bot.config.SpiceBot_Commands.query_prefix).replace("\\", '').split("|")
bot.config.core.prefix_list.extend(bot.config.SpiceBot_Commands.query_prefix)
@ -98,17 +98,17 @@ def setup_google(bot):
def setup_startupmonologue(bot):
logs.log('SpiceBot_StartupMonologue', "Initial Setup processing")
events.startup_add([
events.BOT_STARTUPMONOLOGUE_CONNECTED,
events.BOT_STARTUPMONOLOGUE_CHANNELS,
events.BOT_STARTUPMONOLOGUE_COMMANDS,
events.BOT_STARTUPMONOLOGUE_AI,
botevents.startup_add([
botevents.BOT_STARTUPMONOLOGUE_CONNECTED,
botevents.BOT_STARTUPMONOLOGUE_CHANNELS,
botevents.BOT_STARTUPMONOLOGUE_COMMANDS,
botevents.BOT_STARTUPMONOLOGUE_AI,
])
def setup_channels(bot):
logs.log('SpiceBot_Channels', "Setting Up Configuration")
events.startup_add([events.BOT_CHANNELS])
botevents.startup_add([botevents.BOT_CHANNELS])
bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
@ -122,7 +122,7 @@ def setup_ai(bot):
logs.log('SpiceBot_AI', "Setting Up Configuration")
bot.config.define_section("SpiceBot_AI", SpiceBot_AI_MainSection, validate=False)
bot.config.aibrain = os.path.join(bot.config.homedir, bot.config.core.basename + '.aibrain.brn')
events.startup_add([events.BOT_AI])
botevents.startup_add([botevents.BOT_AI])
def setup_osd(bot):

View File

@ -18,6 +18,7 @@ def ai_trigger(bot, trigger, botcom):
bot.osd(displayval)
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED])
@sopel.module.rule('(.*)')
def bot_command_rule_ai(bot, trigger):

View File

@ -10,7 +10,6 @@ import spicemanip
import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED])
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('channels', 'channel')
def nickname_comand_channels(bot, trigger, botcom):

View File

@ -14,7 +14,6 @@ import sopel_modules.SpiceBot as SpiceBot
# TODO commands sent in privmsg don't need bot.nick
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('commands', 'command')
def nickname_comand_commands(bot, trigger, botcom):

View File

@ -18,7 +18,6 @@ def query_trigger(bot, trigger, botcom):
bot.osd("I have been programmed to help find new commands by using `?`.")
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun_query('nickname', 'nickname')
@sopel.module.nickname_commands('(.*)')
def query_detection_nick(bot, trigger, botcom):
@ -84,7 +83,6 @@ def query_detection_nick(bot, trigger, botcom):
bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice')
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun_query('module', 'module')
@sopel.module.rule('^\?(.*)')
def query_detection(bot, trigger, botcom):

View File

@ -10,6 +10,7 @@ import sopel.module
import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('database')
def bot_command_database(bot, trigger):
bot.osd("Database is " + SpiceBot.config.db_type)

View File

@ -7,10 +7,13 @@ import sopel.module
import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('help', 'docs', 'wiki')
def bot_command_docs(bot, trigger):
bot.osd(["IRC Modules Repository",
str(SpiceBot.github_dict["url_main"] +
SpiceBot.github_dict["repo_owner"] + "/" +
SpiceBot.github_dict["repo_name"] +
SpiceBot.github_dict["url_path_wiki"])])
sb_git_url = str(
SpiceBot.github_dict["url_main"] +
SpiceBot.github_dict["repo_owner"] + "/" +
SpiceBot.github_dict["repo_name"] +
SpiceBot.github_dict["url_path_wiki"]
)
bot.osd(["IRC Modules Repository", sb_git_url])

View File

@ -12,7 +12,6 @@ import spicemanip
import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOGS])
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('logs', 'debug')
def bot_command_logs(bot, trigger, botcom):

View File

@ -7,16 +7,23 @@ import sopel.module
import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED])
@sopel.module.rule(r"""(?:)u/
(
(?:\\/ | [^/])+
)
""")
def bot_command_reddit_user(bot, trigger):
message = SpiceBot.reddit.prerun(trigger)
bot.osd(message)
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED])
@sopel.module.rule(r"""(?:)r/
(
(?:\\/ | [^/])+
)
""")
def bot_command_reddit_syntax(bot, trigger):
def bot_command_reddit_subreddit(bot, trigger):
message = SpiceBot.reddit.prerun(trigger)
bot.osd(message)

View File

@ -5,6 +5,7 @@ These are the core SpiceBot Classes
This module contains references only for other modules to utilize.
"""
# pylama:ignore=W0401,W0611
from .CommandsQuery import *
from .Commands import *

View File

@ -5,6 +5,7 @@ These are the core SpiceBot Classes
This module contains references only for other modules to utilize.
"""
# pylama:ignore=W0401,W0611
from .Channels import *
from .Users import *

View File

@ -1,5 +1,6 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
# pylama:ignore=W0401,W0611
from .Patches import *