test
This commit is contained in:
parent
004180a7f6
commit
09ab9b0d88
@ -23,3 +23,4 @@ install_requires =
|
|||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
sopel.plugins =
|
sopel.plugins =
|
||||||
SpiceBotCore = sopel_SpiceBotCore
|
SpiceBotCore = sopel_SpiceBotCore
|
||||||
|
SpiceBotStartup = sopel_SpiceBotStartup
|
||||||
|
|||||||
@ -6,14 +6,11 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import pathlib
|
import pathlib
|
||||||
from threading import Thread
|
|
||||||
|
|
||||||
from sopel import plugin
|
from sopel import plugin
|
||||||
|
|
||||||
from .SBCore import SpiceBotCore_OBJ
|
from .SBCore import SpiceBotCore_OBJ
|
||||||
|
|
||||||
__import__('pkg_resources').declare_namespace(__name__)
|
|
||||||
|
|
||||||
SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
|
SCRIPT_DIR = pathlib.Path(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
sb = SpiceBotCore_OBJ(SCRIPT_DIR)
|
sb = SpiceBotCore_OBJ(SCRIPT_DIR)
|
||||||
@ -30,73 +27,3 @@ def sb_nickname_command(bot, trigger):
|
|||||||
bot.say("%s" % sb.versions.dict)
|
bot.say("%s" % sb.versions.dict)
|
||||||
|
|
||||||
sb.osd("test", trigger.sender)
|
sb.osd("test", trigger.sender)
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
Events
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
@plugin.event("001")
|
|
||||||
@plugin.rule('.*')
|
|
||||||
def welcome_setup_start(bot, trigger):
|
|
||||||
sb.comms.ircbackend_initialize(bot)
|
|
||||||
|
|
||||||
|
|
||||||
@plugin.event(sb.events.BOT_CONNECTED)
|
|
||||||
@plugin.rule('.*')
|
|
||||||
def bot_events_start_set_hostmask(bot, trigger):
|
|
||||||
sb.comms.hostmask_set(bot)
|
|
||||||
|
|
||||||
|
|
||||||
@plugin.event(sb.events.BOT_WELCOME, sb.events.BOT_READY, sb.events.BOT_CONNECTED, sb.events.BOT_LOADED)
|
|
||||||
@plugin.rule('.*')
|
|
||||||
def bot_events_complete(bot, trigger):
|
|
||||||
"""This is here simply to log to stderr that this was recieved."""
|
|
||||||
sb.logger.info('SpiceBot_Events: %s' % trigger.args[1])
|
|
||||||
|
|
||||||
|
|
||||||
@plugin.event(sb.events.RPL_WELCOME)
|
|
||||||
@plugin.rule('.*')
|
|
||||||
def bot_events_connected(bot, trigger):
|
|
||||||
|
|
||||||
# Handling for connection count
|
|
||||||
sb.events.dict["RPL_WELCOME_Count"] += 1
|
|
||||||
if sb.events.dict["RPL_WELCOME_Count"] > 1:
|
|
||||||
sb.events.trigger(bot, sb.events.BOT_RECONNECTED, "Bot ReConnected to IRC")
|
|
||||||
else:
|
|
||||||
sb.events.trigger(bot, sb.events.BOT_WELCOME, "Welcome to the SpiceBot Events System")
|
|
||||||
|
|
||||||
"""For items tossed in a queue, this will trigger them accordingly"""
|
|
||||||
Thread(target=events_thread, args=(bot,)).start()
|
|
||||||
|
|
||||||
|
|
||||||
def events_thread(bot):
|
|
||||||
while True:
|
|
||||||
if len(sb.events.dict["trigger_queue"]):
|
|
||||||
pretriggerdict = sb.events.dict["trigger_queue"][0]
|
|
||||||
sb.events.dispatch(bot, pretriggerdict)
|
|
||||||
try:
|
|
||||||
del sb.events.dict["trigger_queue"][0]
|
|
||||||
except IndexError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@plugin.event(sb.events.BOT_WELCOME)
|
|
||||||
@plugin.rule('.*')
|
|
||||||
def bot_events_start(bot, trigger):
|
|
||||||
"""This stage is redundant, but shows the system is working."""
|
|
||||||
sb.events.trigger(bot, sb.events.BOT_READY, "Ready To Process plugin setup procedures")
|
|
||||||
|
|
||||||
"""Here, we wait until we are in at least one channel"""
|
|
||||||
while not len(list(bot.channels.keys())) > 0:
|
|
||||||
pass
|
|
||||||
sb.events.trigger(bot, sb.events.BOT_CONNECTED, "Bot Connected to IRC")
|
|
||||||
|
|
||||||
|
|
||||||
@sb.events.startup_check_ready()
|
|
||||||
@plugin.event(sb.events.BOT_READY)
|
|
||||||
@plugin.rule('.*')
|
|
||||||
def bot_events_startup_complete(bot, trigger):
|
|
||||||
"""All events registered as required for startup have completed"""
|
|
||||||
sb.events.trigger(bot, sb.events.BOT_LOADED, "All registered plugins setup procedures have completed")
|
|
||||||
|
|||||||
81
sopel_SpiceBotStartup/__init__.py
Normal file
81
sopel_SpiceBotStartup/__init__.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
# coding=utf8
|
||||||
|
"""SpiceBot
|
||||||
|
A Niche Wrapper around Sopel
|
||||||
|
"""
|
||||||
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
|
||||||
|
from threading import Thread
|
||||||
|
|
||||||
|
from sopel import plugin
|
||||||
|
|
||||||
|
from sopel_SpiceBotCore import sb
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
Events
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.event("001")
|
||||||
|
@plugin.rule('.*')
|
||||||
|
def welcome_setup_start(bot, trigger):
|
||||||
|
sb.comms.ircbackend_initialize(bot)
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.event(sb.events.BOT_CONNECTED)
|
||||||
|
@plugin.rule('.*')
|
||||||
|
def bot_events_start_set_hostmask(bot, trigger):
|
||||||
|
sb.comms.hostmask_set(bot)
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.event(sb.events.BOT_WELCOME, sb.events.BOT_READY, sb.events.BOT_CONNECTED, sb.events.BOT_LOADED)
|
||||||
|
@plugin.rule('.*')
|
||||||
|
def bot_events_complete(bot, trigger):
|
||||||
|
"""This is here simply to log to stderr that this was recieved."""
|
||||||
|
sb.logger.info('SpiceBot_Events: %s' % trigger.args[1])
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.event(sb.events.RPL_WELCOME)
|
||||||
|
@plugin.rule('.*')
|
||||||
|
def bot_events_connected(bot, trigger):
|
||||||
|
|
||||||
|
# Handling for connection count
|
||||||
|
sb.events.dict["RPL_WELCOME_Count"] += 1
|
||||||
|
if sb.events.dict["RPL_WELCOME_Count"] > 1:
|
||||||
|
sb.events.trigger(bot, sb.events.BOT_RECONNECTED, "Bot ReConnected to IRC")
|
||||||
|
else:
|
||||||
|
sb.events.trigger(bot, sb.events.BOT_WELCOME, "Welcome to the SpiceBot Events System")
|
||||||
|
|
||||||
|
"""For items tossed in a queue, this will trigger them accordingly"""
|
||||||
|
Thread(target=events_thread, args=(bot,)).start()
|
||||||
|
|
||||||
|
|
||||||
|
def events_thread(bot):
|
||||||
|
while True:
|
||||||
|
if len(sb.events.dict["trigger_queue"]):
|
||||||
|
pretriggerdict = sb.events.dict["trigger_queue"][0]
|
||||||
|
sb.events.dispatch(bot, pretriggerdict)
|
||||||
|
try:
|
||||||
|
del sb.events.dict["trigger_queue"][0]
|
||||||
|
except IndexError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@plugin.event(sb.events.BOT_WELCOME)
|
||||||
|
@plugin.rule('.*')
|
||||||
|
def bot_events_start(bot, trigger):
|
||||||
|
"""This stage is redundant, but shows the system is working."""
|
||||||
|
sb.events.trigger(bot, sb.events.BOT_READY, "Ready To Process plugin setup procedures")
|
||||||
|
|
||||||
|
"""Here, we wait until we are in at least one channel"""
|
||||||
|
while not len(list(bot.channels.keys())) > 0:
|
||||||
|
pass
|
||||||
|
sb.events.trigger(bot, sb.events.BOT_CONNECTED, "Bot Connected to IRC")
|
||||||
|
|
||||||
|
|
||||||
|
@sb.events.startup_check_ready()
|
||||||
|
@plugin.event(sb.events.BOT_READY)
|
||||||
|
@plugin.rule('.*')
|
||||||
|
def bot_events_startup_complete(bot, trigger):
|
||||||
|
"""All events registered as required for startup have completed"""
|
||||||
|
sb.events.trigger(bot, sb.events.BOT_LOADED, "All registered plugins setup procedures have completed")
|
||||||
Loading…
Reference in New Issue
Block a user