Assemble Internal Logging Feature

This commit is contained in:
deathbybandaid 2019-05-03 15:24:39 -04:00
parent f135d4a81d
commit 01bff54b98
3 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,57 @@
# coding=utf-8
from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.module
from sopel.tools import stderr
import spicemanip
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, command_permissions_check, inlist, inlist_match
def configure(config):
pass
def setup(bot):
stderr("[SpiceBot_Logs] Starting Setup Procedure")
bot.memory['SpiceBot_Logs'] = {}
@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), trigger.sender, 'action')
def bot_logging(bot, logtype, logentry):
if 'SpiceBot_Logs' not in bot.memory:
bot.memory['SpiceBot_Logs'] = {}
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]

View File

@ -0,0 +1,8 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
from .Logs import *
__author__ = 'Sam Zick'
__email__ = 'sam@deathbybandaid.net'
__version__ = '0.1.1'

View File

@ -111,6 +111,26 @@ def inlist(bot, searchterm, searchlist):
return False
def inlist_match(bot, searchterm, searchlist):
# verify we are searching a list
if isinstance(searchlist, collections.abc.KeysView) or isinstance(searchlist, dict):
searchlist = [x for x in searchlist]
if not isinstance(searchlist, list):
searchlist = [searchlist]
rebuildlist = []
for searchitem in searchlist:
rebuildlist.append(str(searchitem))
searchterm = str(searchterm)
if searchterm in rebuildlist:
return searchterm
else:
for searching in rebuildlist:
if searching.lower() == searchterm.lower():
return searching
return searchterm
"""Channel Functions"""