mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 06:29:54 -05:00
commit
9ea10b3804
@ -9,18 +9,6 @@ import spicemanip
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, bot_privs
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('owners', 'owner')
|
||||
def bot_command_owners(bot, trigger):
|
||||
bot_command_process(bot, trigger)
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
# coding=utf8
|
||||
"""Sopel_BotEvents
|
||||
|
||||
Sopel BotEvents is a poor mans way to create module load order dependencies
|
||||
"""
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
import threading
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
# TODO add custom pretrigger events
|
||||
bot_logging(bot, 'Sopel_BotEvents', "Starting Module Events Logging")
|
||||
|
||||
threading.Thread(target=setup_thread, args=(bot,)).start()
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
if "Sopel_BotEvents" in bot.memory:
|
||||
del bot.memory["Sopel_BotEvents"]
|
||||
|
||||
|
||||
def setup_thread(bot):
|
||||
if "Sopel_BotEvents" not in bot.memory:
|
||||
bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []}
|
||||
|
||||
|
||||
def list_bot_events(bot, list_type):
|
||||
if "Sopel_BotEvents" not in bot.memory:
|
||||
bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []}
|
||||
return bot.memory["Sopel_BotEvents"][list_type]
|
||||
|
||||
|
||||
def check_bot_events(bot, listreq):
|
||||
if "Sopel_BotEvents" not in bot.memory:
|
||||
bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []}
|
||||
if not isinstance(listreq, list):
|
||||
listreq = [str(listreq)]
|
||||
for requirement in listreq:
|
||||
if requirement not in bot.memory["Sopel_BotEvents"]["loaded"]:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def set_bot_event(bot, addonreq):
|
||||
if "Sopel_BotEvents" not in bot.memory:
|
||||
bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []}
|
||||
if not isinstance(addonreq, list):
|
||||
addonreq = [str(addonreq)]
|
||||
|
||||
bot.memory["Sopel_BotEvents"]["loaded"].extend(addonreq)
|
||||
|
||||
|
||||
def startup_bot_event(bot, addonreq):
|
||||
if "Sopel_BotEvents" not in bot.memory:
|
||||
bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []}
|
||||
if not isinstance(addonreq, list):
|
||||
addonreq = [str(addonreq)]
|
||||
|
||||
bot.memory["Sopel_BotEvents"]["startup"].extend(addonreq)
|
||||
|
||||
|
||||
def check_bot_startup(bot):
|
||||
if "Sopel_BotEvents" not in bot.memory:
|
||||
bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []}
|
||||
for startupitem in bot.memory["Sopel_BotEvents"]["startup"]:
|
||||
if startupitem not in bot.memory["Sopel_BotEvents"]["loaded"]:
|
||||
return False
|
||||
return True
|
||||
@ -1,25 +0,0 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from .BotEvents import check_bot_events, startup_bot_event, set_bot_event
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
import time
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_connection(bot, trigger):
|
||||
|
||||
if check_bot_events(bot, ["startup_complete"]):
|
||||
return
|
||||
startup_bot_event(bot, "connected")
|
||||
|
||||
while not len(bot.channels.keys()) > 0:
|
||||
pass
|
||||
time.sleep(1)
|
||||
|
||||
set_bot_event(bot, "connected")
|
||||
bot_logging(bot, 'Sopel_BotEvents', "Connected to IRC")
|
||||
@ -1,19 +0,0 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
from .BotEvents import set_bot_event, check_bot_startup
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_complete(bot, trigger):
|
||||
|
||||
while not check_bot_startup(bot):
|
||||
pass
|
||||
|
||||
set_bot_event(bot, "startup_complete")
|
||||
bot_logging(bot, 'Sopel_BotEvents', "Module Events Logging Complete")
|
||||
@ -1,15 +0,0 @@
|
||||
# coding=utf8
|
||||
"""Sopel_BotEvents
|
||||
|
||||
Sopel BotEvents is a poor mans way to create module load order dependencies
|
||||
"""
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .BotEvents import *
|
||||
from .Connected import *
|
||||
from .Startup_Complete import *
|
||||
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
__version__ = '0.1.1'
|
||||
@ -6,18 +6,17 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
|
||||
import sopel.module
|
||||
from sopel.config.types import StaticSection, ValidatedAttribute, ListAttribute
|
||||
|
||||
from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event
|
||||
|
||||
import time
|
||||
|
||||
import spicemanip
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import (
|
||||
sopel_triggerargs, inlist, topic_compile, channel_privs,
|
||||
join_all_channels, chanadmin_all_channels, channel_list_current,
|
||||
bot_logging
|
||||
)
|
||||
|
||||
import spicemanip
|
||||
|
||||
import time
|
||||
|
||||
|
||||
class SpiceBot_Channels_MainSection(StaticSection):
|
||||
announcenew = ValidatedAttribute('announcenew', default=False)
|
||||
@ -35,20 +34,13 @@ def configure(config):
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot_logging(bot, 'SpiceBot_Channels', "Initial Setup processing")
|
||||
|
||||
startup_bot_event(bot, "SpiceBot_Channels")
|
||||
bot_logging(bot, 'SpiceBot_Channels', "Starting setup procedure")
|
||||
bot_events_startup_register(bot, ['2001'])
|
||||
|
||||
bot.config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
|
||||
|
||||
if 'SpiceBot_Channels' not in bot.memory:
|
||||
bot.memory['SpiceBot_Channels'] = dict()
|
||||
if 'channels' not in bot.memory['SpiceBot_Channels'].keys():
|
||||
bot.memory['SpiceBot_Channels']['channels'] = dict()
|
||||
if 'InitialProcess' not in bot.memory['SpiceBot_Channels'].keys():
|
||||
bot.memory['SpiceBot_Channels']['InitialProcess'] = False
|
||||
if 'ProcessLock' not in bot.memory['SpiceBot_Channels'].keys():
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = False
|
||||
if "SpiceBot_Channels" not in bot.memory:
|
||||
bot.memory["SpiceBot_Channels"] = {"channels": {}, "InitialProcess": False, "ProcessLock": False}
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
@ -56,9 +48,10 @@ def shutdown(bot):
|
||||
del bot.memory["SpiceBot_Channels"]
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.event('1003')
|
||||
@sopel.module.rule('.*')
|
||||
def trigger_channel_list_initial(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
# Unkickable
|
||||
bot.write(('SAMODE', bot.nick, '+q'))
|
||||
@ -80,7 +73,7 @@ def trigger_channel_list_initial(bot, trigger):
|
||||
channel_list_current(bot)
|
||||
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot_logging(bot, 'SpiceBot_Channels', "Channel listing finished! " + str(foundchannelcount) + " channel(s) found.")
|
||||
set_bot_event(bot, "SpiceBot_Channels")
|
||||
bot_events_trigger(bot, 2001, "SpiceBot_Channels")
|
||||
|
||||
join_all_channels(bot)
|
||||
chanadmin_all_channels(bot)
|
||||
@ -89,156 +82,32 @@ def trigger_channel_list_initial(bot, trigger):
|
||||
del bot.memory['SpiceBot_Channels']['channels']["*"]
|
||||
|
||||
while True:
|
||||
time.sleep(1800)
|
||||
oldlist = list(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot.write(['LIST'])
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
try:
|
||||
time.sleep(1800)
|
||||
oldlist = list(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot.write(['LIST'])
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
|
||||
while bot.memory['SpiceBot_Channels']['ProcessLock']:
|
||||
pass
|
||||
while bot.memory['SpiceBot_Channels']['ProcessLock']:
|
||||
pass
|
||||
|
||||
newlist = [item.lower() for item in oldlist if item.lower() not in bot.memory['SpiceBot_Channels']['channels']]
|
||||
if "*" in newlist:
|
||||
newlist.remove("*")
|
||||
if len(newlist) and bot.config.SpiceBot_Channels.announcenew:
|
||||
bot.osd(["The Following channel(s) are new:", spicemanip.main(newlist, 'andlist')], bot.channels.keys())
|
||||
newlist = [item.lower() for item in oldlist if item.lower() not in bot.memory['SpiceBot_Channels']['channels']]
|
||||
if "*" in newlist:
|
||||
newlist.remove("*")
|
||||
if len(newlist) and bot.config.SpiceBot_Channels.announcenew:
|
||||
bot.osd(["The Following channel(s) are new:", spicemanip.main(newlist, 'andlist')], bot.channels.keys())
|
||||
|
||||
join_all_channels(bot)
|
||||
join_all_channels(bot)
|
||||
|
||||
chanadmin_all_channels(bot)
|
||||
chanadmin_all_channels(bot)
|
||||
|
||||
if "*" in bot.memory['SpiceBot_Channels']['channels']:
|
||||
del bot.memory['SpiceBot_Channels']['channels']["*"]
|
||||
if "*" in bot.memory['SpiceBot_Channels']['channels']:
|
||||
del bot.memory['SpiceBot_Channels']['channels']["*"]
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
|
||||
@sopel.module.event('321')
|
||||
@sopel.module.event('2001')
|
||||
@sopel.module.rule('.*')
|
||||
def watch_chanlist_start(bot, trigger):
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
|
||||
|
||||
@sopel.module.event('322')
|
||||
@sopel.module.rule('.*')
|
||||
def watch_chanlist_populate(bot, trigger):
|
||||
channel, _, topic = trigger.args[1:]
|
||||
if channel.lower() not in bot.memory['SpiceBot_Channels']['channels']:
|
||||
bot.memory['SpiceBot_Channels']['channels'][channel.lower()] = dict()
|
||||
bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['name'] = channel
|
||||
bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['topic'] = topic_compile(topic)
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
|
||||
|
||||
@sopel.module.event('323')
|
||||
@sopel.module.rule('.*')
|
||||
def watch_chanlist_complete(bot, trigger):
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = False
|
||||
if not bot.memory['SpiceBot_Channels']['InitialProcess']:
|
||||
bot.memory['SpiceBot_Channels']['InitialProcess'] = True
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('channels', 'channel')
|
||||
def nickname_comand_channels(bot, trigger):
|
||||
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
|
||||
|
||||
if not len(triggerargs):
|
||||
commandused = 'list'
|
||||
else:
|
||||
commandused = spicemanip.main(triggerargs, 1).lower()
|
||||
|
||||
triggerargs = spicemanip.main(triggerargs, '2+', 'list')
|
||||
|
||||
channel_list_current(bot)
|
||||
|
||||
if commandused == 'list':
|
||||
chanlist = spicemanip.main(bot.channels.keys(), 'andlist')
|
||||
bot.osd("You can find me in " + chanlist)
|
||||
return
|
||||
|
||||
elif commandused == 'total':
|
||||
botcount = len(bot.channels.keys())
|
||||
servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot.osd("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
||||
return
|
||||
|
||||
elif commandused == 'random':
|
||||
channel = spicemanip.main(bot.memory['SpiceBot_Channels']['channels'], 'random')
|
||||
topic = bot.memory['SpiceBot_Channels']['channels'][channel]['topic']
|
||||
msg = ["Random channel for you: {}.".format(bot.memory['SpiceBot_Channels']['channels'][channel]['name'])]
|
||||
if topic and not topic.isspace():
|
||||
msg.append("The topic is: {}".format(topic))
|
||||
else:
|
||||
msg.append("Its topic is empty.")
|
||||
bot.osd(msg)
|
||||
return
|
||||
|
||||
elif commandused == 'update':
|
||||
if not trigger.admin:
|
||||
bot.osd("You do not have permission to update the channel listing.")
|
||||
return
|
||||
bot.write(['LIST'])
|
||||
bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."])
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
while bot.memory['SpiceBot_Channels']['ProcessLock']:
|
||||
pass
|
||||
join_all_channels(bot)
|
||||
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.")
|
||||
return
|
||||
|
||||
elif commandused == 'topic':
|
||||
if not len(triggerargs):
|
||||
bot.osd("Channel name input missing.")
|
||||
return
|
||||
channel = spicemanip.main(triggerargs, 1)
|
||||
if not inlist(bot, channel.lower(), bot.memory['SpiceBot_Channels']['channels'].keys()):
|
||||
bot.osd("Channel name {} not valid.".format(channel))
|
||||
return
|
||||
topic = bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['topic']
|
||||
channel = bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['name']
|
||||
bot.osd("Topic for {}: {}".format(channel, topic))
|
||||
return
|
||||
|
||||
if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']:
|
||||
if not len(triggerargs):
|
||||
if trigger.is_privmsg:
|
||||
bot.osd("Channel name required.")
|
||||
return
|
||||
else:
|
||||
channel = trigger.sender
|
||||
else:
|
||||
channel = spicemanip.main(triggerargs, 1)
|
||||
if not inlist(bot, channel.lower(), bot.memory['SpiceBot_Channels']['channels'].keys()):
|
||||
bot.osd("Channel name {} not valid.".format(channel))
|
||||
return
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||
return
|
||||
|
||||
privlist = channel_privs(bot, channel, commandused.upper())
|
||||
dispmsg = []
|
||||
if not len(privlist):
|
||||
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
||||
else:
|
||||
oplist = spicemanip.main(privlist, 'andlist')
|
||||
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
|
||||
# Users List
|
||||
if commandused == 'users':
|
||||
channel = spicemanip.main(triggerargs, 1)
|
||||
if not inlist(bot, channel.lower(), bot.memory['SpiceBot_Channels']['channels'].keys()):
|
||||
bot.osd("Channel name {} not valid.".format(channel))
|
||||
return
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see user list.".format(channel))
|
||||
return
|
||||
dispmsg = []
|
||||
if not len(bot.channels[channel].privileges.keys()):
|
||||
dispmsg.append("There are no Channel users for " + str(channel))
|
||||
else:
|
||||
userslist = spicemanip.main(bot.channels[channel].privileges.keys(), 'andlist')
|
||||
dispmsg.append("Channel users for " + str(channel) + " are: " + userslist)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
def bot_events_setup(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
124
sopel_modules/SpiceBot_Channels/Channels_Command.py
Normal file
124
sopel_modules/SpiceBot_Channels/Channels_Command.py
Normal file
@ -0,0 +1,124 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
import spicemanip
|
||||
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_check
|
||||
from sopel_modules.SpiceBot_SBTools import (
|
||||
sopel_triggerargs, inlist, channel_privs,
|
||||
join_all_channels, channel_list_current,
|
||||
)
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('channels', 'channel')
|
||||
def nickname_comand_channels(bot, trigger):
|
||||
|
||||
while not bot_events_check(bot, '1004'):
|
||||
pass
|
||||
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
|
||||
|
||||
if not len(triggerargs):
|
||||
commandused = 'list'
|
||||
else:
|
||||
commandused = spicemanip.main(triggerargs, 1).lower()
|
||||
|
||||
triggerargs = spicemanip.main(triggerargs, '2+', 'list')
|
||||
|
||||
channel_list_current(bot)
|
||||
|
||||
if commandused == 'list':
|
||||
chanlist = spicemanip.main(bot.channels.keys(), 'andlist')
|
||||
bot.osd("You can find me in " + chanlist)
|
||||
return
|
||||
|
||||
elif commandused == 'total':
|
||||
botcount = len(bot.channels.keys())
|
||||
servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot.osd("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
||||
return
|
||||
|
||||
elif commandused == 'random':
|
||||
channel = spicemanip.main(bot.memory['SpiceBot_Channels']['channels'], 'random')
|
||||
topic = bot.memory['SpiceBot_Channels']['channels'][channel]['topic']
|
||||
msg = ["Random channel for you: {}.".format(bot.memory['SpiceBot_Channels']['channels'][channel]['name'])]
|
||||
if topic and not topic.isspace():
|
||||
msg.append("The topic is: {}".format(topic))
|
||||
else:
|
||||
msg.append("Its topic is empty.")
|
||||
bot.osd(msg)
|
||||
return
|
||||
|
||||
elif commandused == 'update':
|
||||
if not trigger.admin:
|
||||
bot.osd("You do not have permission to update the channel listing.")
|
||||
return
|
||||
bot.write(['LIST'])
|
||||
bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."])
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
while bot.memory['SpiceBot_Channels']['ProcessLock']:
|
||||
pass
|
||||
join_all_channels(bot)
|
||||
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.")
|
||||
return
|
||||
|
||||
elif commandused == 'topic':
|
||||
if not len(triggerargs):
|
||||
bot.osd("Channel name input missing.")
|
||||
return
|
||||
channel = spicemanip.main(triggerargs, 1)
|
||||
if not inlist(bot, channel.lower(), bot.memory['SpiceBot_Channels']['channels'].keys()):
|
||||
bot.osd("Channel name {} not valid.".format(channel))
|
||||
return
|
||||
topic = bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['topic']
|
||||
channel = bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['name']
|
||||
bot.osd("Topic for {}: {}".format(channel, topic))
|
||||
return
|
||||
|
||||
if commandused.upper() in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']:
|
||||
if not len(triggerargs):
|
||||
if trigger.is_privmsg:
|
||||
bot.osd("Channel name required.")
|
||||
return
|
||||
else:
|
||||
channel = trigger.sender
|
||||
else:
|
||||
channel = spicemanip.main(triggerargs, 1)
|
||||
if not inlist(bot, channel.lower(), bot.memory['SpiceBot_Channels']['channels'].keys()):
|
||||
bot.osd("Channel name {} not valid.".format(channel))
|
||||
return
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||
return
|
||||
|
||||
privlist = channel_privs(bot, channel, commandused.upper())
|
||||
dispmsg = []
|
||||
if not len(privlist):
|
||||
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
||||
else:
|
||||
oplist = spicemanip.main(privlist, 'andlist')
|
||||
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
|
||||
# Users List
|
||||
if commandused == 'users':
|
||||
channel = spicemanip.main(triggerargs, 1)
|
||||
if not inlist(bot, channel.lower(), bot.memory['SpiceBot_Channels']['channels'].keys()):
|
||||
bot.osd("Channel name {} not valid.".format(channel))
|
||||
return
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see user list.".format(channel))
|
||||
return
|
||||
dispmsg = []
|
||||
if not len(bot.channels[channel].privileges.keys()):
|
||||
dispmsg.append("There are no Channel users for " + str(channel))
|
||||
else:
|
||||
userslist = spicemanip.main(bot.channels[channel].privileges.keys(), 'andlist')
|
||||
dispmsg.append("Channel users for " + str(channel) + " are: " + userslist)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
32
sopel_modules/SpiceBot_Channels/Channels_Parsing.py
Normal file
32
sopel_modules/SpiceBot_Channels/Channels_Parsing.py
Normal file
@ -0,0 +1,32 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import topic_compile
|
||||
|
||||
|
||||
@sopel.module.event('321')
|
||||
@sopel.module.rule('.*')
|
||||
def watch_chanlist_start(bot, trigger):
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
|
||||
|
||||
@sopel.module.event('322')
|
||||
@sopel.module.rule('.*')
|
||||
def watch_chanlist_populate(bot, trigger):
|
||||
channel, _, topic = trigger.args[1:]
|
||||
if channel.lower() not in bot.memory['SpiceBot_Channels']['channels']:
|
||||
bot.memory['SpiceBot_Channels']['channels'][channel.lower()] = dict()
|
||||
bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['name'] = channel
|
||||
bot.memory['SpiceBot_Channels']['channels'][channel.lower()]['topic'] = topic_compile(topic)
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||
|
||||
|
||||
@sopel.module.event('323')
|
||||
@sopel.module.rule('.*')
|
||||
def watch_chanlist_complete(bot, trigger):
|
||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = False
|
||||
if not bot.memory['SpiceBot_Channels']['InitialProcess']:
|
||||
bot.memory['SpiceBot_Channels']['InitialProcess'] = True
|
||||
@ -4,3 +4,5 @@
|
||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
||||
|
||||
from .Channels import *
|
||||
from .Channels_Command import *
|
||||
from .Channels_Parsing import *
|
||||
|
||||
@ -6,41 +6,19 @@ import sopel
|
||||
import sopel.module
|
||||
|
||||
import os
|
||||
from difflib import SequenceMatcher
|
||||
from operator import itemgetter
|
||||
import threading
|
||||
|
||||
|
||||
from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events, bot_logging
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
import spicemanip
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot_logging(bot, 'SpiceBot_CommandsQuery', "Evaluating Core Commands List")
|
||||
|
||||
threading.Thread(target=setup_thread, args=(bot,)).start()
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
if "SpiceBot_CommandsQuery" in bot.memory:
|
||||
del bot.memory["SpiceBot_CommandsQuery"]
|
||||
|
||||
|
||||
def setup_thread(bot):
|
||||
bot_logging(bot, 'SpiceBot_CommandsQuery', "Starting setup procedure")
|
||||
bot_events_startup_register(bot, ['2002'])
|
||||
|
||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
||||
bot.memory['SpiceBot_CommandsQuery'] = dict()
|
||||
|
||||
if 'counts' not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'] = dict()
|
||||
|
||||
if 'commands' not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'] = dict()
|
||||
bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}}
|
||||
|
||||
for comtype in ['module', 'nickname', 'rule']:
|
||||
if comtype not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
@ -134,159 +112,62 @@ def setup_thread(bot):
|
||||
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
||||
filelinelist.append(validcomdict)
|
||||
|
||||
for atlinefound in filelinelist:
|
||||
|
||||
comtype = atlinefound["comtype"]
|
||||
validcoms = atlinefound["validcoms"]
|
||||
|
||||
if len(filelinelist):
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][comtype] += 1
|
||||
|
||||
# default command to filename
|
||||
if "validcoms" not in dict_from_file.keys():
|
||||
dict_from_file["validcoms"] = validcoms
|
||||
for atlinefound in filelinelist:
|
||||
|
||||
maincom = dict_from_file["validcoms"][0]
|
||||
if len(dict_from_file["validcoms"]) > 1:
|
||||
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
|
||||
else:
|
||||
comaliases = []
|
||||
comtype = atlinefound["comtype"]
|
||||
validcoms = atlinefound["validcoms"]
|
||||
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file
|
||||
for comalias in comaliases:
|
||||
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom}
|
||||
# default command to filename
|
||||
if "validcoms" not in dict_from_file.keys():
|
||||
dict_from_file["validcoms"] = validcoms
|
||||
|
||||
maincom = dict_from_file["validcoms"][0]
|
||||
if len(dict_from_file["validcoms"]) > 1:
|
||||
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
|
||||
else:
|
||||
comaliases = []
|
||||
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][maincom] = dict_from_file
|
||||
for comalias in comaliases:
|
||||
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][comtype][comalias] = {"aliasfor": maincom}
|
||||
|
||||
for comtype in ['module', 'nickname', 'rule']:
|
||||
bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.")
|
||||
|
||||
while not check_bot_events(bot, ["startup_complete"]):
|
||||
pass
|
||||
bot_events_trigger(bot, 2002, "SpiceBot_CommandsQuery")
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
if "SpiceBot_CommandsQuery" in bot.memory:
|
||||
del bot.memory["SpiceBot_CommandsQuery"]
|
||||
|
||||
|
||||
@sopel.module.event('1004')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_complete(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
for comtype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
if comtype not in ['module', 'nickname', 'rule']:
|
||||
bot_logging(bot, 'SpiceBot_CommandsQuery', "Found " + str(len(bot.memory['SpiceBot_CommandsQuery']['commands'][comtype].keys())) + " " + comtype + " commands.")
|
||||
|
||||
set_bot_event(bot, "SpiceBot_CommandsQuery")
|
||||
|
||||
|
||||
@sopel.module.rule('^\?(.*)')
|
||||
def query_detection(bot, trigger):
|
||||
|
||||
while "SpiceBot_CommandsQuery" not in bot.memory:
|
||||
pass
|
||||
|
||||
# command must start with
|
||||
if not str(trigger).startswith(tuple(['?'])):
|
||||
return
|
||||
|
||||
commands_list = dict()
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys():
|
||||
if com not in commands_list.keys():
|
||||
commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com]
|
||||
|
||||
triggerargsarray = spicemanip.main(trigger, 'create')
|
||||
|
||||
# command issued, check if valid
|
||||
querycommand = spicemanip.main(triggerargsarray, 1).lower()[1:]
|
||||
if len(querycommand) == 1:
|
||||
commandlist = []
|
||||
for command in commands_list.keys():
|
||||
if command.lower().startswith(querycommand):
|
||||
commandlist.append(command)
|
||||
if commandlist == []:
|
||||
bot.notice("No commands match " + str(querycommand) + ".", trigger.nick)
|
||||
return
|
||||
else:
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif querycommand.endswith(tuple(["+"])):
|
||||
querycommand = querycommand[:-1]
|
||||
if querycommand not in commands_list.keys():
|
||||
bot.notice("The " + str(querycommand) + " does not appear to be valid.")
|
||||
return
|
||||
realcom = querycommand
|
||||
if "aliasfor" in commands_list[querycommand].keys():
|
||||
realcom = commands_list[querycommand]["aliasfor"]
|
||||
validcomlist = commands_list[realcom]["validcoms"]
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif querycommand.endswith(tuple(['?'])):
|
||||
querycommand = querycommand[:-1]
|
||||
sim_com, sim_num = [], []
|
||||
for com in commands_list.keys():
|
||||
similarlevel = SequenceMatcher(None, querycommand.lower(), com.lower()).ratio()
|
||||
sim_com.append(com)
|
||||
sim_num.append(similarlevel)
|
||||
sim_num, sim_com = (list(x) for x in zip(*sorted(zip(sim_num, sim_com), key=itemgetter(0))))
|
||||
closestmatch = spicemanip.main(sim_com, 'reverse', "list")
|
||||
listnumb, relist = 1, []
|
||||
for item in closestmatch:
|
||||
if listnumb <= 10:
|
||||
relist.append(str(item))
|
||||
listnumb += 1
|
||||
bot.notice("The following commands may match " + str(querycommand) + ": " + spicemanip.main(relist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif querycommand in commands_list.keys():
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + str(querycommand) + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif not querycommand:
|
||||
return
|
||||
|
||||
else:
|
||||
commandlist = []
|
||||
for command in commands_list.keys():
|
||||
if command.lower().startswith(querycommand):
|
||||
commandlist.append(command)
|
||||
if commandlist == []:
|
||||
bot.notice("No commands match " + str(querycommand) + ".", trigger.nick)
|
||||
return
|
||||
else:
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
|
||||
|
||||
def commandsquery_register_type(bot, command_type):
|
||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
||||
bot.memory['SpiceBot_CommandsQuery'] = dict()
|
||||
|
||||
if 'counts' not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'] = dict()
|
||||
|
||||
if 'commands' not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'] = dict()
|
||||
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict()
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] += 1
|
||||
|
||||
|
||||
def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
|
||||
|
||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
||||
bot.memory['SpiceBot_CommandsQuery'] = {"counts": {}, "commands": {}}
|
||||
|
||||
if not isinstance(validcoms, list):
|
||||
validcoms = [validcoms]
|
||||
|
||||
if 'SpiceBot_CommandsQuery' not in bot.memory:
|
||||
bot.memory['SpiceBot_CommandsQuery'] = dict()
|
||||
|
||||
if 'counts' not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'] = dict()
|
||||
|
||||
if 'commands' not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'] = dict()
|
||||
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery'].keys():
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict()
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] = 0
|
||||
if command_type not in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][command_type] = dict()
|
||||
bot.memory['SpiceBot_CommandsQuery']['counts'][command_type] += 1
|
||||
|
||||
dict_from_file = dict()
|
||||
@ -309,3 +190,9 @@ def commandsquery_register(bot, command_type, validcoms, aliasfor=None):
|
||||
for comalias in comaliases:
|
||||
if comalias not in bot.memory['SpiceBot_CommandsQuery']['commands'][command_type].keys():
|
||||
bot.memory['SpiceBot_CommandsQuery']['commands'][command_type][comalias] = {"aliasfor": aliasfor}
|
||||
|
||||
|
||||
@sopel.module.event('2002')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_setup(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
90
sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py
Normal file
90
sopel_modules/SpiceBot_CommandsQuery/QueryCommand.py
Normal file
@ -0,0 +1,90 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel
|
||||
import sopel.module
|
||||
|
||||
from difflib import SequenceMatcher
|
||||
from operator import itemgetter
|
||||
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_check
|
||||
|
||||
import spicemanip
|
||||
|
||||
|
||||
@sopel.module.rule('^\?(.*)')
|
||||
def query_detection(bot, trigger):
|
||||
|
||||
while not bot_events_check(bot, '2002'):
|
||||
pass
|
||||
|
||||
commands_list = dict()
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys():
|
||||
if com not in commands_list.keys():
|
||||
commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com]
|
||||
|
||||
triggerargsarray = spicemanip.main(trigger, 'create')
|
||||
|
||||
# command issued, check if valid
|
||||
querycommand = spicemanip.main(triggerargsarray, 1).lower()[1:]
|
||||
if len(querycommand) == 1:
|
||||
commandlist = []
|
||||
for command in commands_list.keys():
|
||||
if command.lower().startswith(querycommand):
|
||||
commandlist.append(command)
|
||||
if commandlist == []:
|
||||
bot.notice("No commands match " + str(querycommand) + ".", trigger.nick)
|
||||
return
|
||||
else:
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif querycommand.endswith(tuple(["+"])):
|
||||
querycommand = querycommand[:-1]
|
||||
if querycommand not in commands_list.keys():
|
||||
bot.notice("The " + str(querycommand) + " does not appear to be valid.")
|
||||
return
|
||||
realcom = querycommand
|
||||
if "aliasfor" in commands_list[querycommand].keys():
|
||||
realcom = commands_list[querycommand]["aliasfor"]
|
||||
validcomlist = commands_list[realcom]["validcoms"]
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif querycommand.endswith(tuple(['?'])):
|
||||
querycommand = querycommand[:-1]
|
||||
sim_com, sim_num = [], []
|
||||
for com in commands_list.keys():
|
||||
similarlevel = SequenceMatcher(None, querycommand.lower(), com.lower()).ratio()
|
||||
sim_com.append(com)
|
||||
sim_num.append(similarlevel)
|
||||
sim_num, sim_com = (list(x) for x in zip(*sorted(zip(sim_num, sim_com), key=itemgetter(0))))
|
||||
closestmatch = spicemanip.main(sim_com, 'reverse', "list")
|
||||
listnumb, relist = 1, []
|
||||
for item in closestmatch:
|
||||
if listnumb <= 10:
|
||||
relist.append(str(item))
|
||||
listnumb += 1
|
||||
bot.notice("The following commands may match " + str(querycommand) + ": " + spicemanip.main(relist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif querycommand in commands_list.keys():
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + str(querycommand) + ".", trigger.nick)
|
||||
return
|
||||
|
||||
elif not querycommand:
|
||||
return
|
||||
|
||||
else:
|
||||
commandlist = []
|
||||
for command in commands_list.keys():
|
||||
if command.lower().startswith(querycommand):
|
||||
commandlist.append(command)
|
||||
if commandlist == []:
|
||||
bot.notice("No commands match " + str(querycommand) + ".", trigger.nick)
|
||||
return
|
||||
else:
|
||||
bot.notice("The following commands match " + str(querycommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick)
|
||||
return
|
||||
@ -6,6 +6,7 @@ Sopel Commands Query responds to ? to display commands matching patterns
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .CommandsQuery import *
|
||||
from .QueryCommand import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
|
||||
@ -21,10 +21,6 @@ def setup(bot):
|
||||
SopelDB._create_table = SopelDBCache._create_table
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
class SopelDBCache:
|
||||
|
||||
"""Dynamic Table Creation"""
|
||||
|
||||
@ -6,18 +6,6 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
|
||||
import sopel.module
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
"""Dyanmic Table Creation"""
|
||||
|
||||
|
||||
|
||||
@ -4,21 +4,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
|
||||
import sopel.module
|
||||
|
||||
import spicemanip
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, bot_privs, github_dict
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
from sopel_modules.SpiceBot_SBTools import github_dict
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('help', 'docs', 'wiki')
|
||||
|
||||
72
sopel_modules/SpiceBot_Events/Events.py
Normal file
72
sopel_modules/SpiceBot_Events/Events.py
Normal file
@ -0,0 +1,72 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel.trigger import PreTrigger
|
||||
|
||||
from .System import bot_events_trigger, bot_events_recieved, bot_events_startup_check, bot_events_setup_check
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
import time
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_connection(bot, trigger):
|
||||
bot_events_trigger(bot, 1001, "Welcome to the SpiceBot Events System")
|
||||
|
||||
while not len(bot.channels.keys()) > 0:
|
||||
pass
|
||||
time.sleep(1)
|
||||
bot_events_trigger(bot, 1003, "Bot Connected to IRC")
|
||||
|
||||
|
||||
@sopel.module.event('1001')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_start(bot, trigger):
|
||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1])
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
bot_events_trigger(bot, 1002, "Ready To Process module setup procedures")
|
||||
|
||||
while not bot_events_startup_check(bot):
|
||||
pass
|
||||
bot_events_trigger(bot, 1004, "All registered modules setup procedures have completed")
|
||||
|
||||
|
||||
@sopel.module.event('1002')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_ready(bot, trigger):
|
||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1])
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
|
||||
@sopel.module.event('1003')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_connected(bot, trigger):
|
||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1])
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
bot_events_setup_check(bot)
|
||||
|
||||
while True:
|
||||
try:
|
||||
if len(bot.memory['SpiceBot_Events']["queue"]):
|
||||
number = bot.memory['SpiceBot_Events']["queue"][0]["number"]
|
||||
message = bot.memory['SpiceBot_Events']["queue"][0]["message"]
|
||||
pretrigger = PreTrigger(
|
||||
bot.nick,
|
||||
":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message
|
||||
)
|
||||
bot.dispatch(pretrigger)
|
||||
del bot.memory['SpiceBot_Events']["queue"][0]
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
|
||||
@sopel.module.event('1004')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_complete(bot, trigger):
|
||||
bot_logging(bot, 'SpiceBot_Events', trigger.args[1])
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
90
sopel_modules/SpiceBot_Events/System.py
Normal file
90
sopel_modules/SpiceBot_Events/System.py
Normal file
@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python
|
||||
#coding=utf-8
|
||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
||||
|
||||
# sopel imports
|
||||
import sopel
|
||||
from sopel.trigger import PreTrigger
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot_logging(bot, 'SpiceBot_Events', "Starting setup procedure")
|
||||
bot_events_setup_check(bot)
|
||||
bot_events_startup_register(bot, ['1001', '1002', '1003'])
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
if "SpiceBot_Events" in bot.memory:
|
||||
del bot.memory["SpiceBot_Events"]
|
||||
|
||||
|
||||
def bot_events_trigger(bot, number, message):
|
||||
|
||||
bot_events_setup_check(bot)
|
||||
|
||||
bot.memory["SpiceBot_Events"]["triggers"][str(number)] = message
|
||||
if str(number) in ['1001', '1002', '1003']:
|
||||
pretrigger = PreTrigger(
|
||||
bot.nick,
|
||||
":SpiceBot_Events " + str(number) + " " + str(bot.nick) + " :" + message
|
||||
)
|
||||
bot.dispatch(pretrigger)
|
||||
else:
|
||||
pretriggerdict = {"number": number, "message": message}
|
||||
bot.memory['SpiceBot_Events']["queue"].append(pretriggerdict)
|
||||
|
||||
|
||||
def bot_events_setup_check(bot):
|
||||
if "SpiceBot_Events" not in bot.memory:
|
||||
bot.memory["SpiceBot_Events"] = {"triggers": {}, "startup": [], "loaded": [], "queue": []}
|
||||
|
||||
|
||||
def bot_events_check(bot, listreq):
|
||||
|
||||
bot_events_setup_check(bot)
|
||||
|
||||
if not isinstance(listreq, list):
|
||||
listreq = [str(listreq)]
|
||||
|
||||
for requirement in listreq:
|
||||
if requirement not in bot.memory["SpiceBot_Events"]["loaded"]:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def bot_events_startup_register(bot, addonreq):
|
||||
|
||||
bot_events_setup_check(bot)
|
||||
|
||||
if not isinstance(addonreq, list):
|
||||
addonreq = [str(addonreq)]
|
||||
|
||||
bot.memory["SpiceBot_Events"]["startup"].extend(addonreq)
|
||||
|
||||
|
||||
def bot_events_recieved(bot, number):
|
||||
|
||||
bot_events_setup_check(bot)
|
||||
|
||||
if str(number) not in bot.memory["SpiceBot_Events"]["loaded"]:
|
||||
bot.memory["SpiceBot_Events"]["loaded"].append(str(number))
|
||||
|
||||
|
||||
def bot_events_startup_check(bot):
|
||||
|
||||
bot_events_setup_check(bot)
|
||||
|
||||
notcomplete = []
|
||||
|
||||
for startupitem in bot.memory["SpiceBot_Events"]["startup"]:
|
||||
if str(startupitem) not in bot.memory["SpiceBot_Events"]["loaded"]:
|
||||
notcomplete.append(str(startupitem))
|
||||
|
||||
if len(notcomplete):
|
||||
# bot_logging(bot, 'SpiceBot_Events', str(notcomplete))
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
9
sopel_modules/SpiceBot_Events/__init__.py
Normal file
9
sopel_modules/SpiceBot_Events/__init__.py
Normal file
@ -0,0 +1,9 @@
|
||||
# coding=utf8
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .System import *
|
||||
from .Events import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
__version__ = '0.1.1'
|
||||
@ -7,18 +7,6 @@ import sopel.module
|
||||
import spicemanip
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$')
|
||||
def bot_command_hello(bot, trigger):
|
||||
hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random")
|
||||
|
||||
@ -5,18 +5,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
import sopel.module
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('gender')
|
||||
def bot_command_gender(bot, trigger):
|
||||
bot.osd("If societal genders are binary, my gender is female")
|
||||
|
||||
@ -7,6 +7,7 @@ from sopel import module
|
||||
from .gifsearch import getGif
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_check
|
||||
|
||||
import spicemanip
|
||||
|
||||
@ -14,7 +15,7 @@ import spicemanip
|
||||
@module.commands('gif')
|
||||
def gif_trigger(bot, trigger):
|
||||
|
||||
while "SpiceBot_GifSearch" not in bot.memory:
|
||||
while not bot_events_check(bot, '2003'):
|
||||
pass
|
||||
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger)
|
||||
|
||||
@ -9,12 +9,13 @@ import sopel.module
|
||||
import spicemanip
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_check
|
||||
|
||||
|
||||
@sopel.module.commands('(.*)')
|
||||
def gifapi_triggers(bot, trigger):
|
||||
|
||||
while "SpiceBot_GifSearch" not in bot.memory:
|
||||
while not bot_events_check(bot, '2003'):
|
||||
pass
|
||||
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'prefix_command')
|
||||
|
||||
@ -5,11 +5,11 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
import sopel.module
|
||||
from sopel.config.types import StaticSection, ValidatedAttribute
|
||||
|
||||
from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, startup_bot_event
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
|
||||
|
||||
from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register, commandsquery_register_type
|
||||
from sopel_modules.SpiceBot_CommandsQuery.CommandsQuery import commandsquery_register
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, sopel_triggerargs, bot_logging
|
||||
from sopel_modules.SpiceBot_SBTools import read_directory_json_to_dict, bot_logging
|
||||
|
||||
import spicemanip
|
||||
|
||||
@ -19,7 +19,6 @@ import requests
|
||||
import json
|
||||
from fake_useragent import UserAgent
|
||||
import random
|
||||
import threading
|
||||
|
||||
# user agent and header
|
||||
ua = UserAgent()
|
||||
@ -51,20 +50,8 @@ def configure(config):
|
||||
|
||||
|
||||
def setup(bot):
|
||||
|
||||
bot_logging(bot, 'SpiceBot_GifSearch', "Starting Setup Procedure")
|
||||
|
||||
threading.Thread(target=setup_thread, args=(bot,)).start()
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
if "SpiceBot_GifSearch" in bot.memory:
|
||||
del bot.memory["SpiceBot_GifSearch"]
|
||||
|
||||
|
||||
def setup_thread(bot):
|
||||
|
||||
startup_bot_event(bot, "SpiceBot_GifSearch")
|
||||
bot_events_startup_register(bot, ['2003'])
|
||||
|
||||
if 'SpiceBot_GifSearch' not in bot.memory:
|
||||
bot.memory["SpiceBot_GifSearch"] = {"cache": {}, "badgiflinks": [], 'valid_gif_api_dict': {}}
|
||||
@ -90,29 +77,18 @@ def setup_thread(bot):
|
||||
valid_gif_api_dict[gif_api]["apikey"] = None
|
||||
bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api]
|
||||
|
||||
commandsquery_register_type(bot, "prefix")
|
||||
for prefixcommand in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys():
|
||||
commandsquery_register(bot, "prefix", prefixcommand)
|
||||
for validgifapi in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys():
|
||||
commandsquery_register(bot, "prefix", validgifapi)
|
||||
|
||||
set_bot_event(bot, "SpiceBot_GifSearch")
|
||||
if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys():
|
||||
bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict()
|
||||
|
||||
bot_events_trigger(bot, 2003, "SpiceBot_GifSearch")
|
||||
|
||||
|
||||
@sopel.module.commands('gif')
|
||||
def gif_trigger(bot, trigger):
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger)
|
||||
if triggerargs == []:
|
||||
return bot.osd("Please present a query to search.")
|
||||
|
||||
query = spicemanip.main(trigger.args[1], 0)
|
||||
searchapis = bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys()
|
||||
searchdict = {"query": query, "gifsearch": searchapis}
|
||||
|
||||
gifdict = getGif(bot, searchdict)
|
||||
|
||||
if gifdict["error"]:
|
||||
bot.osd(gifdict["error"])
|
||||
else:
|
||||
bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"])))
|
||||
def shutdown(bot):
|
||||
if "SpiceBot_GifSearch" in bot.memory:
|
||||
del bot.memory["SpiceBot_GifSearch"]
|
||||
|
||||
|
||||
def getGif(bot, searchdict):
|
||||
@ -256,12 +232,13 @@ def getGif(bot, searchdict):
|
||||
try:
|
||||
gifpage = requests.get(gifdict["returnurl"], headers=None)
|
||||
except Exception as e:
|
||||
gifpage = str(e)
|
||||
gifpage = None
|
||||
|
||||
if gifpage and not str(gifpage.status_code).startswith(tuple(["4", "5"])):
|
||||
randombad = False
|
||||
else:
|
||||
bot.memory["SpiceBot_GifSearch"]["badgiflinks"].append(gifdict["returnurl"])
|
||||
bot.memory["SpiceBot_GifSearch"]["badgiflinks"].append(str(gifdict["returnurl"]))
|
||||
newlist = []
|
||||
for tempdict in gifapiresults:
|
||||
if tempdict["returnurl"] != gifdict["returnurl"]:
|
||||
@ -274,3 +251,9 @@ def getGif(bot, searchdict):
|
||||
# return dict
|
||||
gifdict['error'] = None
|
||||
return gifdict
|
||||
|
||||
|
||||
@sopel.module.event('2003')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_setup(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
@ -5,18 +5,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
import sopel.module
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@sopel.module.rule(r'(?i)(Fuck|Screw) (you|off),? $nickname[ \t]*$')
|
||||
def bot_command_srewyou(bot, trigger):
|
||||
bot.osd("Watch your mouth, " + trigger.nick + ", or I'll tell your mother!")
|
||||
|
||||
@ -3,12 +3,10 @@
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
from sopel.tools import stderr
|
||||
from sopel.config.types import StaticSection, ValidatedAttribute
|
||||
|
||||
import spicemanip
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match, bot_logging
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_startup_register, bot_events_recieved, bot_events_trigger
|
||||
|
||||
|
||||
def configure(config):
|
||||
@ -23,23 +21,29 @@ class SpiceBot_Logs_MainSection(StaticSection):
|
||||
def setup(bot):
|
||||
bot_logging(bot, 'SpiceBot_Logs', "Starting Setup Procedure")
|
||||
bot.config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False)
|
||||
if 'SpiceBot_Logs' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs'] = {}
|
||||
|
||||
if 'SpiceBot_Logs_queue' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs_queue'] = []
|
||||
bot_events_startup_register(bot, ['2004'])
|
||||
|
||||
bot_logs_setup_check(bot)
|
||||
|
||||
bot_events_trigger(bot, 2004, "SpiceBot_Logs")
|
||||
|
||||
|
||||
def bot_logs_setup_check(bot):
|
||||
if 'SpiceBot_Logs' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
if "SpiceBot_Logs" in bot.memory:
|
||||
del bot.memory["SpiceBot_Logs"]
|
||||
if "SpiceBot_Logs_queue" in bot.memory:
|
||||
del bot.memory["SpiceBot_Logs_queue"]
|
||||
|
||||
|
||||
@sopel.module.event('001')
|
||||
@sopel.module.event('1003')
|
||||
@sopel.module.rule('.*')
|
||||
def join_log_channel(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
if bot.config.SpiceBot_Logs.logging_channel:
|
||||
channel = bot.config.SpiceBot_Logs.logging_channel
|
||||
if channel not in bot.channels.keys():
|
||||
@ -47,35 +51,18 @@ def join_log_channel(bot, trigger):
|
||||
if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin:
|
||||
bot.write(('SAJOIN', bot.nick, channel))
|
||||
|
||||
if 'SpiceBot_Logs_queue' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs_queue'] = []
|
||||
bot_logs_setup_check(bot)
|
||||
|
||||
while True:
|
||||
if len(bot.memory['SpiceBot_Logs_queue']):
|
||||
bot.say(str(bot.memory['SpiceBot_Logs_queue'][0]), channel)
|
||||
del bot.memory['SpiceBot_Logs_queue'][0]
|
||||
try:
|
||||
if len(bot.memory['SpiceBot_Logs']["queue"]):
|
||||
bot.say(str(bot.memory['SpiceBot_Logs']["queue"][0]), channel)
|
||||
del bot.memory['SpiceBot_Logs']["queue"][0]
|
||||
except KeyError:
|
||||
return
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('logs')
|
||||
def bot_command_action(bot, trigger):
|
||||
|
||||
if not command_permissions_check(bot, trigger, ['admins', 'owner']):
|
||||
bot.say("I was unable to process this Bot Nick command due to privilege issues.")
|
||||
return
|
||||
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
|
||||
|
||||
logtype = spicemanip.main(triggerargs, 1) or None
|
||||
if not logtype or not inlist(bot, logtype, bot.memory['SpiceBot_Logs'].keys()):
|
||||
bot.osd("Current valid log(s) include: " + spicemanip.main(bot.memory['SpiceBot_Logs'].keys(), 'andlist'), trigger.sender, 'action')
|
||||
return
|
||||
|
||||
logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys())
|
||||
|
||||
if len(bot.memory['SpiceBot_Logs'][logtype]) == 0:
|
||||
bot.osd("No logs found for " + str(logtype) + ".")
|
||||
return
|
||||
|
||||
bot.osd("Is Examining " + str(logtype) + " log(s).")
|
||||
for line in bot.memory['SpiceBot_Logs'][logtype]:
|
||||
bot.osd(" " + str(line))
|
||||
@sopel.module.event('2004')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_setup(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
38
sopel_modules/SpiceBot_Logs/Logs_Command.py
Normal file
38
sopel_modules/SpiceBot_Logs/Logs_Command.py
Normal file
@ -0,0 +1,38 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
import spicemanip
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_check
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('logs')
|
||||
def bot_command_action(bot, trigger):
|
||||
|
||||
while not bot_events_check(bot, '2004'):
|
||||
pass
|
||||
|
||||
if not command_permissions_check(bot, trigger, ['admins', 'owner']):
|
||||
bot.say("I was unable to process this Bot Nick command due to privilege issues.")
|
||||
return
|
||||
|
||||
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
|
||||
|
||||
logtype = spicemanip.main(triggerargs, 1) or None
|
||||
if not logtype or not inlist(bot, logtype, bot.memory['SpiceBot_Logs']["logs"].keys()):
|
||||
bot.osd("Current valid log(s) include: " + spicemanip.main(bot.memory['SpiceBot_Logs']["logs"].keys(), 'andlist'), trigger.sender, 'action')
|
||||
return
|
||||
|
||||
logtype = inlist_match(bot, logtype, bot.memory['SpiceBot_Logs'].keys())
|
||||
|
||||
if len(bot.memory['SpiceBot_Logs']["logs"][logtype]) == 0:
|
||||
bot.osd("No logs found for " + str(logtype) + ".")
|
||||
return
|
||||
|
||||
bot.osd("Is Examining " + str(logtype) + " log(s).")
|
||||
for line in bot.memory['SpiceBot_Logs']["logs"][logtype]:
|
||||
bot.osd(" " + str(line))
|
||||
@ -2,6 +2,7 @@
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .Logs import *
|
||||
from .Logs_Command import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
|
||||
@ -9,18 +9,6 @@ import spicemanip
|
||||
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('action')
|
||||
def bot_command_action(bot, trigger):
|
||||
bot_command_process(bot, trigger)
|
||||
|
||||
@ -8,18 +8,6 @@ import sopel.module
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging, spicebot_reload
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('restart')
|
||||
def nickname_comand_restart(bot, trigger):
|
||||
|
||||
|
||||
@ -4,9 +4,6 @@
|
||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
||||
|
||||
import sopel
|
||||
from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP
|
||||
from sopel.tools import stderr
|
||||
HOP = HALFOP
|
||||
|
||||
import collections
|
||||
import re
|
||||
@ -92,24 +89,21 @@ def command_permissions_check(bot, trigger, privslist):
|
||||
|
||||
def bot_logging(bot, logtype, logentry):
|
||||
|
||||
if 'SpiceBot_Logs_queue' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs_queue'] = []
|
||||
if 'SpiceBot_Logs' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs'] = {"logs": {}, "queue": []}
|
||||
|
||||
logmessage = "[" + logtype + "] " + logentry + ""
|
||||
|
||||
bot.memory['SpiceBot_Logs_queue'].append(logmessage)
|
||||
bot.memory['SpiceBot_Logs']["queue"].append(logmessage)
|
||||
|
||||
stderr("\n" + logmessage + "\n")
|
||||
sopel.tools.stderr(logmessage)
|
||||
|
||||
if 'SpiceBot_Logs' not in bot.memory:
|
||||
bot.memory['SpiceBot_Logs'] = {}
|
||||
if logtype not in bot.memory['SpiceBot_Logs']["logs"].keys():
|
||||
bot.memory['SpiceBot_Logs']["logs"][logtype] = []
|
||||
|
||||
if logtype not in bot.memory['SpiceBot_Logs'].keys():
|
||||
bot.memory['SpiceBot_Logs'][logtype] = []
|
||||
|
||||
bot.memory['SpiceBot_Logs'][logtype].append(logentry)
|
||||
if len(bot.memory['SpiceBot_Logs'][logtype]) > 10:
|
||||
del bot.memory['SpiceBot_Logs'][logtype][0]
|
||||
bot.memory['SpiceBot_Logs']["logs"][logtype].append(logentry)
|
||||
if len(bot.memory['SpiceBot_Logs']["logs"][logtype]) > 10:
|
||||
del bot.memory['SpiceBot_Logs']["logs"][logtype][0]
|
||||
|
||||
|
||||
"""
|
||||
@ -146,6 +140,7 @@ def humanized_time(countdownseconds):
|
||||
if not displaymsg:
|
||||
return "just now"
|
||||
return displaymsg
|
||||
eval(year + day + hour + minute + second)
|
||||
|
||||
|
||||
"""List Manipulation Functions"""
|
||||
@ -208,9 +203,13 @@ def channel_privs(bot, channel, privtype):
|
||||
privnum = bot.channels[channel].privileges[user] or 0
|
||||
except KeyError:
|
||||
privnum = 0
|
||||
if (privnum == eval(privtype) or
|
||||
(privnum >= eval(privtype) and privtype == 'OWNER') or
|
||||
(privnum >= eval(privtype) and privnum < eval("OWNER") and privtype == 'ADMIN')):
|
||||
if privtype == 'HOP':
|
||||
privtypeeval = sopel.module.HALFOP
|
||||
else:
|
||||
privtypeeval = eval("sopel.module." + privtype)
|
||||
if (privnum == privtypeeval or
|
||||
(privnum >= privtypeeval and privtype == 'OWNER') or
|
||||
(privnum >= privtypeeval and privnum < sopel.module.OWNER and privtype == 'ADMIN')):
|
||||
privlist.append(user)
|
||||
return privlist
|
||||
|
||||
@ -229,7 +228,7 @@ def chanadmin_all_channels(bot):
|
||||
for channel in bot.channels.keys():
|
||||
if channel not in bot.config.SpiceBot_Channels.chanignore:
|
||||
if bot.config.SpiceBot_Channels.operadmin:
|
||||
if not bot.channels[channel].privileges[bot.nick] < ADMIN:
|
||||
if not bot.channels[channel].privileges[bot.nick] < sopel.module.ADMIN:
|
||||
bot.write(('SAMODE', channel, "+a", bot.nick))
|
||||
else:
|
||||
bot.part(channel)
|
||||
@ -242,7 +241,6 @@ def channel_list_current(bot):
|
||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()] = dict()
|
||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()]['name'] = str(channel)
|
||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()]['topic'] = topic_compile(topic)
|
||||
channel_privs(bot, channel)
|
||||
|
||||
if "*" in bot.memory['SpiceBot_Channels']:
|
||||
bot.memory['SpiceBot_Channels'].remove("*")
|
||||
|
||||
14
sopel_modules/SpiceBot_SopelPatches/Patches.py
Normal file
14
sopel_modules/SpiceBot_SopelPatches/Patches.py
Normal file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
# coding=utf-8
|
||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
||||
|
||||
# sopel imports
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot_logging(bot, 'Sopel_Patch', "Patching Sopels built-in url_callbacks")
|
||||
if 'url_callbacks' not in bot.memory:
|
||||
bot.memory['url_callbacks'] = sopel.tools.SopelMemory()
|
||||
8
sopel_modules/SpiceBot_SopelPatches/__init__.py
Normal file
8
sopel_modules/SpiceBot_SopelPatches/__init__.py
Normal file
@ -0,0 +1,8 @@
|
||||
# coding=utf8
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .Patches import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
__version__ = '0.1.1'
|
||||
@ -2,82 +2,21 @@
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from sopel import module
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot_Botevents.BotEvents import set_bot_event, check_bot_events
|
||||
|
||||
from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging
|
||||
import time
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_startup_register
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
|
||||
def setup(bot):
|
||||
pass
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', "Starting setup procedure")
|
||||
bot_events_startup_register(bot, ['2010', '2011'])
|
||||
|
||||
if 'SpiceBot_StartupMonologue' not in bot.memory:
|
||||
bot.memory['SpiceBot_StartupMonologue'] = []
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@module.event('001')
|
||||
@module.rule('.*')
|
||||
@module.thread(True)
|
||||
def bot_startup_monologue(bot, trigger):
|
||||
|
||||
while not check_bot_events(bot, ["connected"]):
|
||||
pass
|
||||
|
||||
if check_bot_events(bot, ["SpiceBot_StartupMonologue"]):
|
||||
startup_reconnect(bot, trigger)
|
||||
else:
|
||||
startup_fresh(bot, trigger)
|
||||
|
||||
|
||||
def startup_fresh(bot, trigger):
|
||||
|
||||
# Startup
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration")
|
||||
bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION')
|
||||
|
||||
startupcomplete = [bot.nick + " startup complete"]
|
||||
|
||||
while not check_bot_events(bot, ["SpiceBot_CommandsQuery"]):
|
||||
pass
|
||||
|
||||
availablecomsnum, availablecomsfiles = 0, 0
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys())
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype]
|
||||
|
||||
startupcomplete.append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
||||
|
||||
while not check_bot_events(bot, ["SpiceBot_Channels"]):
|
||||
pass
|
||||
|
||||
botcount = len(bot.channels.keys())
|
||||
servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
startupcomplete.append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
||||
|
||||
while not check_bot_events(bot, ["startup_complete"]):
|
||||
pass
|
||||
|
||||
timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"])
|
||||
startupcomplete.append("Startup took " + timesince)
|
||||
|
||||
# Announce to chan, then handle some closing stuff
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete")
|
||||
bot.osd(startupcomplete, bot.channels.keys())
|
||||
|
||||
set_bot_event(bot, "SpiceBot_StartupMonologue")
|
||||
|
||||
|
||||
def startup_reconnect(bot, trigger):
|
||||
|
||||
# Startup
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " has reconnected.")
|
||||
bot.osd(" has reconnected.", bot.channels.keys(), 'ACTION')
|
||||
@sopel.module.event('2005', '2010', '2011')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_setup(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
# coding=utf-8
|
||||
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger
|
||||
from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging
|
||||
import time
|
||||
|
||||
|
||||
@sopel.module.event('1003')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_start(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
# Startup
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " is now starting. Please wait while I load my configuration")
|
||||
bot.osd(" is now starting. Please wait while I load my configuration.", bot.channels.keys(), 'ACTION')
|
||||
|
||||
bot.memory['SpiceBot_StartupMonologue'].append(bot.nick + " startup complete")
|
||||
|
||||
|
||||
@sopel.module.event('2002')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_commands(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
availablecomsnum, availablecomsfiles = 0, 0
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
||||
availablecomsnum += len(bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys())
|
||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['counts'].keys():
|
||||
availablecomsfiles += bot.memory['SpiceBot_CommandsQuery']['counts'][commandstype]
|
||||
|
||||
bot.memory['SpiceBot_StartupMonologue'].append("There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', "There are " + str(availablecomsnum) + " commands available in " + str(availablecomsfiles) + " files.")
|
||||
|
||||
bot_events_trigger(bot, 2011, "SpiceBot_StartupMonologue")
|
||||
|
||||
|
||||
@sopel.module.event('2001')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_channels(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
botcount = len(bot.channels.keys())
|
||||
servercount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||
bot.memory['SpiceBot_StartupMonologue'].append("I am in " + str(botcount) + " of " + str(servercount) + " channel(s) available on this server.")
|
||||
|
||||
bot_events_trigger(bot, 2010, "SpiceBot_StartupMonologue")
|
||||
|
||||
|
||||
@sopel.module.event('1004')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_display(bot, trigger):
|
||||
bot_events_recieved(bot, trigger.event)
|
||||
|
||||
timesince = humanized_time(time.time() - bot.memory["SpiceBot_Uptime"])
|
||||
bot.memory['SpiceBot_StartupMonologue'].append("Startup took " + timesince)
|
||||
|
||||
# Announce to chan, then handle some closing stuff
|
||||
bot_logging(bot, 'SpiceBot_StartupMonologue', bot.nick + " startup complete")
|
||||
bot.memory['SpiceBot_StartupMonologue'].insert(0, " startup complete")
|
||||
|
||||
bot.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys(), 'ACTION')
|
||||
|
||||
bot_events_trigger(bot, 2005, "SpiceBot_StartupMonologue")
|
||||
@ -6,6 +6,7 @@ Sopel Startup Monologue displays to all channels that the bot is online
|
||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||
|
||||
from .StartupMonologue import *
|
||||
from .StartupMonologue_Display import *
|
||||
|
||||
__author__ = 'Sam Zick'
|
||||
__email__ = 'sam@deathbybandaid.net'
|
||||
|
||||
@ -29,10 +29,6 @@ def setup(bot):
|
||||
bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
@sopel.module.nickname_commands('update')
|
||||
def nickname_comand_update(bot, trigger):
|
||||
|
||||
@ -75,8 +71,9 @@ def spicebot_update(bot, deps=False):
|
||||
pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch)
|
||||
|
||||
bot_logging(bot, 'SpiceBot_Update', "Running `" + pipcommand + "`")
|
||||
for line in os.popen(pipcommand).read().split('\n'):
|
||||
bot_logging(bot, 'SpiceBot_Update', " " + line)
|
||||
# for line in os.popen(pipcommand).read().split('\n'):
|
||||
# bot_logging(bot, 'SpiceBot_Update', " " + line)
|
||||
os.system(pipcommand)
|
||||
|
||||
stock_modules_begone(bot)
|
||||
|
||||
|
||||
@ -11,10 +11,6 @@ from sopel_modules.SpiceBot_SBTools import humanized_time
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
|
||||
def configure(config):
|
||||
pass
|
||||
|
||||
|
||||
def setup(bot):
|
||||
if 'SpiceBot_Uptime' not in bot.memory:
|
||||
now = time.time()
|
||||
|
||||
@ -54,11 +54,6 @@ def setup(bot):
|
||||
bot.config.define_section("MAXTARGCONFIG", MAXTARGCONFIG, validate=False)
|
||||
|
||||
|
||||
def shutdown(bot):
|
||||
pass
|
||||
|
||||
|
||||
# RPL_ISUPPORT = '005'
|
||||
@module.event('005')
|
||||
@module.rule('.*')
|
||||
def parse_event_005(bot, trigger):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user