mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 06:29:54 -05:00
too many updates for one test, but oh well
This commit is contained in:
parent
8304350b1a
commit
4e46bbc0a2
@ -5,11 +5,13 @@ This is the SpiceBot Channels system.
|
|||||||
"""
|
"""
|
||||||
import sopel
|
import sopel
|
||||||
import re
|
import re
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
class BotChannels():
|
class BotChannels():
|
||||||
"""This Logs all channels known to the server"""
|
"""This Logs all channels known to the server"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.lock = threading.Lock()
|
||||||
self.channel_lock = False
|
self.channel_lock = False
|
||||||
self.dict = {
|
self.dict = {
|
||||||
"list": {},
|
"list": {},
|
||||||
@ -23,16 +25,20 @@ class BotChannels():
|
|||||||
self.channel_lock = True
|
self.channel_lock = True
|
||||||
|
|
||||||
def channel_list_recieve_input(self, trigger):
|
def channel_list_recieve_input(self, trigger):
|
||||||
|
self.lock.acquire()
|
||||||
channel, _, topic = trigger.args[1:]
|
channel, _, topic = trigger.args[1:]
|
||||||
if channel.lower() not in self.dict['list'].keys():
|
if channel.lower() not in self.dict['list'].keys():
|
||||||
self.dict['list'][channel.lower()] = dict()
|
self.dict['list'][channel.lower()] = dict()
|
||||||
self.dict['list'][channel.lower()]['name'] = channel
|
self.dict['list'][channel.lower()]['name'] = channel
|
||||||
self.dict['list'][channel.lower()]['topic'] = self.topic_compile(topic)
|
self.dict['list'][channel.lower()]['topic'] = self.topic_compile(topic)
|
||||||
self.channel_lock = True
|
self.channel_lock = True
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
def channel_list_recieve_finish(self):
|
def channel_list_recieve_finish(self):
|
||||||
|
self.lock.acquire()
|
||||||
if not self.dict['InitialProcess']:
|
if not self.dict['InitialProcess']:
|
||||||
self.dict['InitialProcess'] = True
|
self.dict['InitialProcess'] = True
|
||||||
|
self.lock.release()
|
||||||
self.channel_lock = False
|
self.channel_lock = False
|
||||||
|
|
||||||
def topic_compile(self, topic):
|
def topic_compile(self, topic):
|
||||||
@ -49,7 +55,9 @@ class BotChannels():
|
|||||||
if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist and channel.startswith("#"):
|
if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist and channel.startswith("#"):
|
||||||
bot.part(channel, "Leaving Empty Channel")
|
bot.part(channel, "Leaving Empty Channel")
|
||||||
if channel.lower() in self.dict['list']:
|
if channel.lower() in self.dict['list']:
|
||||||
|
self.lock.acquire()
|
||||||
del self.dict['list'][channel.lower()]
|
del self.dict['list'][channel.lower()]
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
def join_all_channels(self, bot):
|
def join_all_channels(self, bot):
|
||||||
if bot.config.SpiceBot_Channels.joinall:
|
if bot.config.SpiceBot_Channels.joinall:
|
||||||
|
|||||||
@ -5,13 +5,19 @@ This is the SpiceBot Commands system.
|
|||||||
|
|
||||||
This Class stores commands in an easy to access manner
|
This Class stores commands in an easy to access manner
|
||||||
"""
|
"""
|
||||||
|
import sopel
|
||||||
|
import os
|
||||||
|
import threading
|
||||||
|
|
||||||
import spicemanip
|
import spicemanip
|
||||||
|
|
||||||
|
from .Logs import logs
|
||||||
|
|
||||||
|
|
||||||
class BotCommands():
|
class BotCommands():
|
||||||
"""This Logs all commands known to the bot"""
|
"""This Logs all commands known to the bot"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.lock = threading.Lock()
|
||||||
self.dict = {
|
self.dict = {
|
||||||
"counts": 0,
|
"counts": 0,
|
||||||
"commands": {
|
"commands": {
|
||||||
@ -19,17 +25,20 @@ class BotCommands():
|
|||||||
'nickname': {},
|
'nickname': {},
|
||||||
'rule': {}
|
'rule': {}
|
||||||
},
|
},
|
||||||
"nickrules": []
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def commandsquery_register(self, bot, command_type, validcoms, aliasfor=None):
|
def register(self, bot, command_dict):
|
||||||
|
|
||||||
|
self.lock.acquire()
|
||||||
|
|
||||||
|
command_type = command_dict["comtype"]
|
||||||
|
validcoms = command_dict["validcoms"]
|
||||||
|
|
||||||
if not isinstance(validcoms, list):
|
if not isinstance(validcoms, list):
|
||||||
validcoms = [validcoms]
|
validcoms = [validcoms]
|
||||||
|
|
||||||
if command_type not in self.dict['commands'].keys():
|
if command_type not in self.dict['commands'].keys():
|
||||||
self.dict['commands'][command_type] = dict()
|
self.dict['commands'][command_type] = dict()
|
||||||
self.dict['counts'] += 1
|
|
||||||
|
|
||||||
dict_from_file = dict()
|
dict_from_file = dict()
|
||||||
|
|
||||||
@ -37,20 +46,139 @@ class BotCommands():
|
|||||||
if "validcoms" not in dict_from_file.keys():
|
if "validcoms" not in dict_from_file.keys():
|
||||||
dict_from_file["validcoms"] = validcoms
|
dict_from_file["validcoms"] = validcoms
|
||||||
|
|
||||||
if not aliasfor:
|
maincom = dict_from_file["validcoms"][0]
|
||||||
|
if len(dict_from_file["validcoms"]) > 1:
|
||||||
maincom = dict_from_file["validcoms"][0]
|
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
|
||||||
if len(dict_from_file["validcoms"]) > 1:
|
|
||||||
comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list')
|
|
||||||
else:
|
|
||||||
comaliases = []
|
|
||||||
self.dict['commands'][command_type][maincom] = dict_from_file
|
|
||||||
else:
|
else:
|
||||||
comaliases = validcoms
|
comaliases = []
|
||||||
|
|
||||||
|
self.dict['commands'][command_type][maincom] = dict_from_file
|
||||||
for comalias in comaliases:
|
for comalias in comaliases:
|
||||||
if comalias not in self.dict['commands'][command_type].keys():
|
if comalias not in self.dict['commands'][command_type].keys():
|
||||||
self.dict['commands'][command_type][comalias] = {"aliasfor": aliasfor}
|
self.dict['commands'][command_type][comalias] = {"aliasfor": maincom}
|
||||||
|
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
|
def module_directory_list(self, bot):
|
||||||
|
filepathlisting = []
|
||||||
|
|
||||||
|
# main Modules directory
|
||||||
|
main_dir = os.path.dirname(os.path.abspath(sopel.__file__))
|
||||||
|
modules_dir = os.path.join(main_dir, 'modules')
|
||||||
|
filepathlisting.append(modules_dir)
|
||||||
|
|
||||||
|
# Home Directory
|
||||||
|
home_modules_dir = os.path.join(bot.config.homedir, 'modules')
|
||||||
|
if os.path.isdir(home_modules_dir):
|
||||||
|
filepathlisting.append(home_modules_dir)
|
||||||
|
|
||||||
|
# pypi installed
|
||||||
|
try:
|
||||||
|
import sopel_modules
|
||||||
|
for plugin_dir in set(sopel_modules.__path__):
|
||||||
|
for pathname in os.listdir(plugin_dir):
|
||||||
|
pypi_modules_dir = os.path.join(plugin_dir, pathname)
|
||||||
|
filepathlisting.append(pypi_modules_dir)
|
||||||
|
except Exception as e:
|
||||||
|
logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e))
|
||||||
|
|
||||||
|
# Extra directories
|
||||||
|
for directory in bot.config.core.extra:
|
||||||
|
filepathlisting.append(directory)
|
||||||
|
|
||||||
|
return filepathlisting
|
||||||
|
|
||||||
|
def module_files_list(self, bot):
|
||||||
|
filepathlisting = self.module_directory_list(bot)
|
||||||
|
|
||||||
|
filepathlist = []
|
||||||
|
|
||||||
|
for directory in filepathlisting:
|
||||||
|
for pathname in os.listdir(directory):
|
||||||
|
path = os.path.join(directory, pathname)
|
||||||
|
if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')):
|
||||||
|
if pathname not in ["SpiceBot_dummycommand.py"]:
|
||||||
|
filepathlist.append(str(path))
|
||||||
|
|
||||||
|
# CoreTasks
|
||||||
|
main_dir = os.path.dirname(os.path.abspath(sopel.__file__))
|
||||||
|
ct_path = os.path.join(main_dir, 'coretasks.py')
|
||||||
|
filepathlist.append(ct_path)
|
||||||
|
|
||||||
|
return filepathlist
|
||||||
|
|
||||||
|
def module_files_parse(self, bot):
|
||||||
|
filepathlist = self.module_files_list(bot)
|
||||||
|
|
||||||
|
for modulefile in filepathlist:
|
||||||
|
|
||||||
|
module_file_lines = []
|
||||||
|
module_file = open(modulefile, 'r')
|
||||||
|
lines = module_file.readlines()
|
||||||
|
for line in lines:
|
||||||
|
module_file_lines.append(line)
|
||||||
|
module_file.close()
|
||||||
|
|
||||||
|
detected_lines = []
|
||||||
|
for line in module_file_lines:
|
||||||
|
|
||||||
|
if str(line).startswith("@"):
|
||||||
|
line = str(line)[1:]
|
||||||
|
|
||||||
|
if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])):
|
||||||
|
line = str(line).split("commands")[-1]
|
||||||
|
line = "commands" + line
|
||||||
|
detected_lines.append(line)
|
||||||
|
elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])):
|
||||||
|
line = str(line).split("nickname_commands")[-1]
|
||||||
|
line = "nickname_commands" + line
|
||||||
|
detected_lines.append(line)
|
||||||
|
elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])):
|
||||||
|
line = str(line).split("rule")[-1]
|
||||||
|
line = "rule" + line
|
||||||
|
else:
|
||||||
|
line = None
|
||||||
|
|
||||||
|
if line:
|
||||||
|
detected_lines.append(line)
|
||||||
|
|
||||||
|
if len(detected_lines):
|
||||||
|
|
||||||
|
filelinelist = []
|
||||||
|
currentsuccesslines = 0
|
||||||
|
for detected_line in detected_lines:
|
||||||
|
|
||||||
|
# Commands
|
||||||
|
if str(detected_line).startswith("commands"):
|
||||||
|
comtype = "module"
|
||||||
|
validcoms = eval(str(detected_line).split("commands")[-1])
|
||||||
|
elif str(detected_line).startswith("nickname_commands"):
|
||||||
|
comtype = "nickname"
|
||||||
|
validcoms = eval(str(detected_line).split("nickname_commands")[-1])
|
||||||
|
elif str(detected_line).startswith("rule"):
|
||||||
|
comtype = "rule"
|
||||||
|
validcoms = eval(str(detected_line).split("rule")[-1])
|
||||||
|
|
||||||
|
if isinstance(validcoms, tuple):
|
||||||
|
validcoms = list(validcoms)
|
||||||
|
else:
|
||||||
|
validcoms = [validcoms]
|
||||||
|
for regexcom in ["(.*)", '^\?(.*)']:
|
||||||
|
if regexcom in validcoms:
|
||||||
|
while regexcom in validcoms:
|
||||||
|
validcoms.remove(regexcom)
|
||||||
|
|
||||||
|
if len(validcoms):
|
||||||
|
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
||||||
|
filelinelist.append(validcomdict)
|
||||||
|
currentsuccesslines += 1
|
||||||
|
|
||||||
|
if currentsuccesslines:
|
||||||
|
self.dict['counts'] += 1
|
||||||
|
|
||||||
|
if len(filelinelist):
|
||||||
|
for atlinefound in filelinelist:
|
||||||
|
self.register(bot, atlinefound)
|
||||||
|
|
||||||
|
|
||||||
commands = BotCommands()
|
commands = BotCommands()
|
||||||
|
|||||||
@ -10,6 +10,7 @@ self-trigger the bot into performing actions
|
|||||||
|
|
||||||
import sopel
|
import sopel
|
||||||
import functools
|
import functools
|
||||||
|
import threading
|
||||||
|
|
||||||
|
|
||||||
class BotEvents(object):
|
class BotEvents(object):
|
||||||
@ -26,6 +27,7 @@ class BotEvents(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.lock = threading.Lock()
|
||||||
self.RPL_WELCOME = '001' # This is a defined IRC event
|
self.RPL_WELCOME = '001' # This is a defined IRC event
|
||||||
self.BOT_WELCOME = '1001'
|
self.BOT_WELCOME = '1001'
|
||||||
self.BOT_READY = '1002'
|
self.BOT_READY = '1002'
|
||||||
@ -43,9 +45,11 @@ class BotEvents(object):
|
|||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
''' will only get called for undefined attributes '''
|
''' will only get called for undefined attributes '''
|
||||||
|
self.lock.acquire()
|
||||||
eventnumber = max(list(self.dict["assigned_IDs"].keys())) + 1
|
eventnumber = max(list(self.dict["assigned_IDs"].keys())) + 1
|
||||||
self.dict["assigned_IDs"][eventnumber] = str(name)
|
self.dict["assigned_IDs"][eventnumber] = str(name)
|
||||||
setattr(self, name, str(eventnumber))
|
setattr(self, name, str(eventnumber))
|
||||||
|
self.lock.release()
|
||||||
return str(eventnumber)
|
return str(eventnumber)
|
||||||
|
|
||||||
def trigger(self, bot, number, message="SpiceBot_Events"):
|
def trigger(self, bot, number, message="SpiceBot_Events"):
|
||||||
@ -66,6 +70,7 @@ class BotEvents(object):
|
|||||||
self.recieved({"number": number, "message": message})
|
self.recieved({"number": number, "message": message})
|
||||||
|
|
||||||
def recieved(self, trigger):
|
def recieved(self, trigger):
|
||||||
|
self.lock.acquire()
|
||||||
if isinstance(trigger, dict):
|
if isinstance(trigger, dict):
|
||||||
eventnumber = str(trigger["number"])
|
eventnumber = str(trigger["number"])
|
||||||
message = str(trigger["message"])
|
message = str(trigger["message"])
|
||||||
@ -75,6 +80,7 @@ class BotEvents(object):
|
|||||||
if eventnumber not in self.dict["triggers_recieved"]:
|
if eventnumber not in self.dict["triggers_recieved"]:
|
||||||
self.dict["triggers_recieved"][eventnumber] = []
|
self.dict["triggers_recieved"][eventnumber] = []
|
||||||
self.dict["triggers_recieved"][eventnumber].append(message)
|
self.dict["triggers_recieved"][eventnumber].append(message)
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
def check(self, checklist):
|
def check(self, checklist):
|
||||||
if not isinstance(checklist, list):
|
if not isinstance(checklist, list):
|
||||||
@ -85,9 +91,11 @@ class BotEvents(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def startup_add(self, startlist):
|
def startup_add(self, startlist):
|
||||||
|
self.lock.acquire()
|
||||||
if not isinstance(startlist, list):
|
if not isinstance(startlist, list):
|
||||||
startlist = [str(startlist)]
|
startlist = [str(startlist)]
|
||||||
self.dict["startup_required"].extend(startlist)
|
self.dict["startup_required"].extend(startlist)
|
||||||
|
self.lock.release()
|
||||||
|
|
||||||
def startup_check(self):
|
def startup_check(self):
|
||||||
for number in self.dict["startup_required"]:
|
for number in self.dict["startup_required"]:
|
||||||
|
|||||||
@ -6,8 +6,8 @@ This is the SpiceBot Logs system.
|
|||||||
This Class stores logs in an easy to access manner
|
This Class stores logs in an easy to access manner
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
import sopel
|
import sopel
|
||||||
|
import threading
|
||||||
import os
|
import os
|
||||||
import spicemanip
|
import spicemanip
|
||||||
|
|
||||||
@ -15,6 +15,7 @@ import spicemanip
|
|||||||
class BotLogs():
|
class BotLogs():
|
||||||
"""This Is a contained source of log information"""
|
"""This Is a contained source of log information"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.lock = threading.Lock()
|
||||||
self.dict = {
|
self.dict = {
|
||||||
"list": {"Sopel_systemd": [], "Sopel_stdio": []},
|
"list": {"Sopel_systemd": [], "Sopel_stdio": []},
|
||||||
"queue": []
|
"queue": []
|
||||||
@ -24,6 +25,9 @@ class BotLogs():
|
|||||||
}
|
}
|
||||||
|
|
||||||
def log(self, logtype, logentry, stdio=False):
|
def log(self, logtype, logentry, stdio=False):
|
||||||
|
|
||||||
|
self.lock.acquire()
|
||||||
|
|
||||||
logtitle = "[" + logtype + "]"
|
logtitle = "[" + logtype + "]"
|
||||||
logmessage = logtitle + " " + logentry
|
logmessage = logtitle + " " + logentry
|
||||||
|
|
||||||
@ -37,8 +41,16 @@ class BotLogs():
|
|||||||
self.dict["list"][logtype] = []
|
self.dict["list"][logtype] = []
|
||||||
self.dict["list"][logtype].append(logentry)
|
self.dict["list"][logtype].append(logentry)
|
||||||
|
|
||||||
def get_logs(self):
|
self.lock.release()
|
||||||
return []
|
|
||||||
|
def get_logs(self, bot, logtype):
|
||||||
|
if logtype == "Sopel_systemd":
|
||||||
|
logindex = self.systemd_logs_fetch(bot)
|
||||||
|
elif logtype == "Sopel_stdio":
|
||||||
|
logindex = self.stdio_logs_fetch(bot)
|
||||||
|
else:
|
||||||
|
logindex = self.dict["list"][logtype]
|
||||||
|
return logindex
|
||||||
|
|
||||||
def stdio_logs_fetch(self, bot):
|
def stdio_logs_fetch(self, bot):
|
||||||
|
|
||||||
|
|||||||
@ -27,9 +27,6 @@ def bot_command_nick(bot, trigger):
|
|||||||
|
|
||||||
fulltrigger = spicemanip.main(triggerargs, 0).lower()
|
fulltrigger = spicemanip.main(triggerargs, 0).lower()
|
||||||
|
|
||||||
if fulltrigger in SpiceBot.commands.dict['nickrules']:
|
|
||||||
return
|
|
||||||
|
|
||||||
if fulltrigger.lower().startswith("what is"):
|
if fulltrigger.lower().startswith("what is"):
|
||||||
searchterm = spicemanip.main(triggerargs, "3+") or None
|
searchterm = spicemanip.main(triggerargs, "3+") or None
|
||||||
if searchterm:
|
if searchterm:
|
||||||
@ -151,15 +148,3 @@ def bot_command_nick(bot, trigger):
|
|||||||
# bot.osd("I have never seen " + str(target) + ".")
|
# bot.osd("I have never seen " + str(target) + ".")
|
||||||
# TODO
|
# TODO
|
||||||
return
|
return
|
||||||
|
|
||||||
else:
|
|
||||||
|
|
||||||
closestmatches = SpiceBot.similar_list(bot, triggercommand, SpiceBot.commands.dict['commands']["nickname"].keys(), 3, 'reverse')
|
|
||||||
|
|
||||||
if len(closestmatches):
|
|
||||||
closestmatches = spicemanip.main(closestmatches, "andlist")
|
|
||||||
bot.osd("I don't know what you are asking me to do! Did you mean: " + str(closestmatches) + "?")
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
bot.osd("I don't know what you are asking me to do!")
|
|
||||||
return
|
|
||||||
|
|||||||
34
sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands
Normal file
34
sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
|
||||||
|
from .gifsearch import getGif
|
||||||
|
|
||||||
|
import sopel.module
|
||||||
|
|
||||||
|
import spicemanip
|
||||||
|
|
||||||
|
import sopel_modules.SpiceBot as SpiceBot
|
||||||
|
|
||||||
|
|
||||||
|
@SpiceBot.events.check_ready([SpiceBot.events.BOT_GIFSEARCH])
|
||||||
|
@sopel.module.commands('(.*)')
|
||||||
|
def gifapi_triggers(bot, trigger):
|
||||||
|
|
||||||
|
triggerargs, triggercommand = SpiceBot.sopel_triggerargs(bot, trigger, 'prefix_command')
|
||||||
|
|
||||||
|
if triggercommand not in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys():
|
||||||
|
return
|
||||||
|
|
||||||
|
if not len(triggerargs):
|
||||||
|
return bot.osd("Please present a query to search.")
|
||||||
|
|
||||||
|
query = spicemanip.main(triggerargs, 0)
|
||||||
|
searchdict = {"query": query, "gifsearch": triggercommand}
|
||||||
|
|
||||||
|
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"])))
|
||||||
@ -5,8 +5,9 @@ Sopel Gif Search builds a convenient framework for searching for Gifs
|
|||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
|
||||||
from .gif import *
|
from .Gif_Command import *
|
||||||
from .gifapi import *
|
from .Gif_API_Commands import *
|
||||||
|
# from .Gif_Search_Commands import *
|
||||||
from .gifsearch import *
|
from .gifsearch import *
|
||||||
|
|
||||||
__author__ = 'Sam Zick'
|
__author__ = 'Sam Zick'
|
||||||
|
|||||||
@ -70,7 +70,12 @@ def setup(bot):
|
|||||||
bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api]
|
bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api]
|
||||||
|
|
||||||
for validgifapi in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys():
|
for validgifapi in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys():
|
||||||
SpiceBot.commands.commandsquery_register(bot, "prefix", validgifapi)
|
command_dict = {
|
||||||
|
"comtype": "prefix",
|
||||||
|
"validcoms": validgifapi
|
||||||
|
}
|
||||||
|
SpiceBot.commands.dict['counts'] += 1
|
||||||
|
SpiceBot.commands.register(bot, command_dict)
|
||||||
|
|
||||||
if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys():
|
if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys():
|
||||||
bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict()
|
bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict()
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
# coding=utf-8
|
|
||||||
|
|
||||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
|
||||||
|
|
||||||
import sopel.module
|
|
||||||
|
|
||||||
import sopel_modules.SpiceBot as SpiceBot
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
|
||||||
if 'SpiceBot_InvalidCommand' not in bot.memory:
|
|
||||||
bot.memory["SpiceBot_InvalidCommand"] = {"valid": []}
|
|
||||||
|
|
||||||
|
|
||||||
def shutdown(bot):
|
|
||||||
if "SpiceBot_InvalidCommand" in bot.memory:
|
|
||||||
del bot.memory["SpiceBot_InvalidCommand"]
|
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(SpiceBot.events.BOT_LOADED)
|
|
||||||
@sopel.module.rule('.*')
|
|
||||||
def bot_events_complete(bot, trigger):
|
|
||||||
for comtype in SpiceBot.commands.dict['commands'].keys():
|
|
||||||
bot.memory["SpiceBot_InvalidCommand"]["valid"].extend(SpiceBot.commands.dict['commands'][comtype].keys())
|
|
||||||
|
|
||||||
|
|
||||||
@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED, SpiceBot.events.BOT_COMMANDSQUERY])
|
|
||||||
@sopel.module.commands('(.*)')
|
|
||||||
def InvalidCommand_triggers(bot, trigger):
|
|
||||||
return
|
|
||||||
|
|
||||||
triggerargs, triggercommand = SpiceBot.sopel_triggerargs(bot, trigger, 'prefix_command')
|
|
||||||
|
|
||||||
# patch for people typing "...", maybe other stuff, but this verifies that there is still a command here
|
|
||||||
if triggercommand.startswith("."):
|
|
||||||
return
|
|
||||||
|
|
||||||
if triggercommand not in bot.memory["SpiceBot_InvalidCommand"]["valid"]:
|
|
||||||
invalid_display = ["I don't seem to have a command for " + str(triggercommand) + "!"]
|
|
||||||
invalid_display.append("If you have a suggestion for this command, you can run .feature ." + str(triggercommand))
|
|
||||||
invalid_display.append("ADD DESCRIPTION HERE!")
|
|
||||||
bot.osd(invalid_display, trigger.nick, 'notice')
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
# coding=utf8
|
|
||||||
"""Sopel Gif Search
|
|
||||||
|
|
||||||
Sopel Gif Search builds a convenient framework for searching for Gifs
|
|
||||||
"""
|
|
||||||
from __future__ import unicode_literals, absolute_import, division, print_function
|
|
||||||
|
|
||||||
from .InvalidCommand import *
|
|
||||||
|
|
||||||
__author__ = 'Sam Zick'
|
|
||||||
__email__ = 'sam@deathbybandaid.net'
|
|
||||||
__version__ = '0.1.1'
|
|
||||||
@ -34,12 +34,7 @@ def bot_command_logs(bot, trigger):
|
|||||||
|
|
||||||
logtype = SpiceBot.inlist_match(logtype, SpiceBot.logs.dict["list"].keys())
|
logtype = SpiceBot.inlist_match(logtype, SpiceBot.logs.dict["list"].keys())
|
||||||
|
|
||||||
if logtype == "Sopel_systemd":
|
logindex = SpiceBot.logs.get_logs(bot, logtype)
|
||||||
logindex = SpiceBot.logs.systemd_logs_fetch(bot)
|
|
||||||
elif logtype == "Sopel_stdio":
|
|
||||||
logindex = SpiceBot.logs.stdio_logs_fetch(bot)
|
|
||||||
else:
|
|
||||||
logindex = SpiceBot.logs.dict["list"][logtype]
|
|
||||||
|
|
||||||
if not len(logindex):
|
if not len(logindex):
|
||||||
bot.osd("No logs found for " + str(logtype) + ".")
|
bot.osd("No logs found for " + str(logtype) + ".")
|
||||||
|
|||||||
@ -5,156 +5,19 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
|||||||
import sopel
|
import sopel
|
||||||
import sopel.module
|
import sopel.module
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
import sopel_modules.SpiceBot as SpiceBot
|
import sopel_modules.SpiceBot as SpiceBot
|
||||||
|
|
||||||
import spicemanip
|
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
SpiceBot.logs.log('SpiceBot_CommandsQuery', "Starting setup procedure")
|
SpiceBot.logs.log('SpiceBot_Commands', "Starting setup procedure")
|
||||||
SpiceBot.events.startup_add([SpiceBot.events.BOT_COMMANDSQUERY])
|
SpiceBot.events.startup_add([SpiceBot.events.BOT_COMMANDSQUERY])
|
||||||
|
|
||||||
filepathlisting = []
|
SpiceBot.commands.module_files_parse(bot)
|
||||||
|
|
||||||
# main Modules directory
|
|
||||||
main_dir = os.path.dirname(os.path.abspath(sopel.__file__))
|
|
||||||
modules_dir = os.path.join(main_dir, 'modules')
|
|
||||||
filepathlisting.append(modules_dir)
|
|
||||||
|
|
||||||
# Home Directory
|
|
||||||
home_modules_dir = os.path.join(bot.config.homedir, 'modules')
|
|
||||||
if os.path.isdir(home_modules_dir):
|
|
||||||
filepathlisting.append(home_modules_dir)
|
|
||||||
|
|
||||||
# pypi installed
|
|
||||||
try:
|
|
||||||
import sopel_modules
|
|
||||||
for plugin_dir in set(sopel_modules.__path__):
|
|
||||||
for pathname in os.listdir(plugin_dir):
|
|
||||||
pypi_modules_dir = os.path.join(plugin_dir, pathname)
|
|
||||||
filepathlisting.append(pypi_modules_dir)
|
|
||||||
except Exception as e:
|
|
||||||
SpiceBot.logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e))
|
|
||||||
|
|
||||||
# Extra directories
|
|
||||||
filepathlist = []
|
|
||||||
for directory in bot.config.core.extra:
|
|
||||||
filepathlisting.append(directory)
|
|
||||||
|
|
||||||
for directory in filepathlisting:
|
|
||||||
for pathname in os.listdir(directory):
|
|
||||||
path = os.path.join(directory, pathname)
|
|
||||||
if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')):
|
|
||||||
if pathname not in ["SpiceBot_dummycommand.py"]:
|
|
||||||
filepathlist.append(str(path))
|
|
||||||
|
|
||||||
# CoreTasks
|
|
||||||
ct_path = os.path.join(main_dir, 'coretasks.py')
|
|
||||||
filepathlist.append(ct_path)
|
|
||||||
|
|
||||||
for modulefile in filepathlist:
|
|
||||||
|
|
||||||
module_file_lines = []
|
|
||||||
module_file = open(modulefile, 'r')
|
|
||||||
lines = module_file.readlines()
|
|
||||||
for line in lines:
|
|
||||||
module_file_lines.append(line)
|
|
||||||
module_file.close()
|
|
||||||
|
|
||||||
dict_from_file = dict()
|
|
||||||
|
|
||||||
detected_lines = []
|
|
||||||
for line in module_file_lines:
|
|
||||||
|
|
||||||
if str(line).startswith("@"):
|
|
||||||
line = str(line)[1:]
|
|
||||||
|
|
||||||
if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])):
|
|
||||||
line = str(line).split("commands")[-1]
|
|
||||||
line = "commands" + line
|
|
||||||
detected_lines.append(line)
|
|
||||||
elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])):
|
|
||||||
line = str(line).split("nickname_commands")[-1]
|
|
||||||
line = "nickname_commands" + line
|
|
||||||
detected_lines.append(line)
|
|
||||||
elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])):
|
|
||||||
line = str(line).split("rule")[-1]
|
|
||||||
line = "rule" + line
|
|
||||||
else:
|
|
||||||
line = None
|
|
||||||
|
|
||||||
if line:
|
|
||||||
detected_lines.append(line)
|
|
||||||
|
|
||||||
if len(detected_lines):
|
|
||||||
|
|
||||||
filelinelist = []
|
|
||||||
currentsuccesslines = 0
|
|
||||||
for detected_line in detected_lines:
|
|
||||||
|
|
||||||
# Commands
|
|
||||||
if str(detected_line).startswith("commands"):
|
|
||||||
comtype = "module"
|
|
||||||
validcoms = eval(str(detected_line).split("commands")[-1])
|
|
||||||
elif str(detected_line).startswith("nickname_commands"):
|
|
||||||
comtype = "nickname"
|
|
||||||
validcoms = eval(str(detected_line).split("nickname_commands")[-1])
|
|
||||||
elif str(detected_line).startswith("rule"):
|
|
||||||
comtype = "rule"
|
|
||||||
validcoms = eval(str(detected_line).split("rule")[-1])
|
|
||||||
|
|
||||||
if isinstance(validcoms, tuple):
|
|
||||||
validcoms = list(validcoms)
|
|
||||||
else:
|
|
||||||
validcoms = [validcoms]
|
|
||||||
for regexcom in ["(.*)", '^\?(.*)']:
|
|
||||||
if regexcom in validcoms:
|
|
||||||
while regexcom in validcoms:
|
|
||||||
validcoms.remove(regexcom)
|
|
||||||
|
|
||||||
if len(validcoms):
|
|
||||||
validcomdict = {"comtype": comtype, "validcoms": validcoms}
|
|
||||||
filelinelist.append(validcomdict)
|
|
||||||
currentsuccesslines += 1
|
|
||||||
|
|
||||||
if currentsuccesslines:
|
|
||||||
SpiceBot.commands.dict['counts'] += 1
|
|
||||||
|
|
||||||
if len(filelinelist):
|
|
||||||
for atlinefound in filelinelist:
|
|
||||||
|
|
||||||
dict_from_file = dict()
|
|
||||||
|
|
||||||
comtype = atlinefound["comtype"]
|
|
||||||
validcoms = atlinefound["validcoms"]
|
|
||||||
|
|
||||||
# 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 = []
|
|
||||||
|
|
||||||
SpiceBot.commands.dict['commands'][comtype][maincom] = dict_from_file
|
|
||||||
for comalias in comaliases:
|
|
||||||
if comalias not in SpiceBot.commands.dict['commands'][comtype].keys():
|
|
||||||
SpiceBot.commands.dict['commands'][comtype][comalias] = {"aliasfor": maincom}
|
|
||||||
|
|
||||||
for comtype in ['module', 'nickname', 'rule']:
|
for comtype in ['module', 'nickname', 'rule']:
|
||||||
SpiceBot.logs.log('SpiceBot_CommandsQuery', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)
|
SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)
|
||||||
|
|
||||||
for command in SpiceBot.commands.dict['commands']['rule'].keys():
|
SpiceBot.events.trigger(bot, SpiceBot.events.BOT_COMMANDSQUERY, "SpiceBot_Commands")
|
||||||
if command.startswith("$nickname"):
|
|
||||||
command = command.split("$nickname")[-1]
|
|
||||||
if command not in SpiceBot.commands.dict['nickrules']:
|
|
||||||
SpiceBot.commands.dict['nickrules'].append(command)
|
|
||||||
|
|
||||||
SpiceBot.events.trigger(bot, SpiceBot.events.BOT_COMMANDSQUERY, "SpiceBot_CommandsQuery")
|
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(SpiceBot.events.BOT_LOADED)
|
@sopel.module.event(SpiceBot.events.BOT_LOADED)
|
||||||
@ -163,4 +26,4 @@ def bot_events_complete(bot, trigger):
|
|||||||
|
|
||||||
for comtype in SpiceBot.commands.dict['commands'].keys():
|
for comtype in SpiceBot.commands.dict['commands'].keys():
|
||||||
if comtype not in ['module', 'nickname', 'rule']:
|
if comtype not in ['module', 'nickname', 'rule']:
|
||||||
SpiceBot.logs.log('SpiceBot_CommandsQuery', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)
|
SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user