mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
part logic
This commit is contained in:
parent
c6fb848998
commit
48e9228b2a
@ -65,6 +65,8 @@ def trigger_channel_list_initial(bot, trigger):
|
|||||||
# Unkickable
|
# Unkickable
|
||||||
bot.write(('SAMODE', bot.nick, '+q'))
|
bot.write(('SAMODE', bot.nick, '+q'))
|
||||||
|
|
||||||
|
bot_part_empty(bot)
|
||||||
|
|
||||||
bot.write(['LIST'])
|
bot.write(['LIST'])
|
||||||
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
bot.memory['SpiceBot_Channels']['ProcessLock'] = True
|
||||||
|
|
||||||
@ -89,6 +91,7 @@ def trigger_channel_list_initial(bot, trigger):
|
|||||||
if "*" in bot.memory['SpiceBot_Channels']['channels']:
|
if "*" in bot.memory['SpiceBot_Channels']['channels']:
|
||||||
del bot.memory['SpiceBot_Channels']['channels']["*"]
|
del bot.memory['SpiceBot_Channels']['channels']["*"]
|
||||||
|
|
||||||
|
bot_part_empty(bot)
|
||||||
botevents.trigger(bot, botevents.BOT_CHANNELS, "SpiceBot_Channels")
|
botevents.trigger(bot, botevents.BOT_CHANNELS, "SpiceBot_Channels")
|
||||||
|
|
||||||
|
|
||||||
@ -98,6 +101,7 @@ def trigger_channel_list_recurring(bot, trigger):
|
|||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
time.sleep(1800)
|
time.sleep(1800)
|
||||||
|
bot_part_empty(bot)
|
||||||
|
|
||||||
oldlist = list(bot.memory['SpiceBot_Channels']['channels'].keys())
|
oldlist = list(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||||
bot.write(['LIST'])
|
bot.write(['LIST'])
|
||||||
@ -118,14 +122,13 @@ def trigger_channel_list_recurring(bot, trigger):
|
|||||||
|
|
||||||
if "*" in bot.memory['SpiceBot_Channels']['channels']:
|
if "*" in bot.memory['SpiceBot_Channels']['channels']:
|
||||||
del bot.memory['SpiceBot_Channels']['channels']["*"]
|
del bot.memory['SpiceBot_Channels']['channels']["*"]
|
||||||
|
bot_part_empty(bot)
|
||||||
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(botevents.BOT_CHANNELS)
|
def bot_part_empty(bot):
|
||||||
@sopel.module.rule('.*')
|
|
||||||
def bot_part_empty(bot, trigger):
|
|
||||||
"""Don't stay in empty channels"""
|
"""Don't stay in empty channels"""
|
||||||
ignorepartlist = []
|
ignorepartlist = []
|
||||||
if bot.config.SpiceBot_Logs.logging_channel:
|
if bot.config.SpiceBot_Logs.logging_channel:
|
||||||
|
|||||||
@ -11,6 +11,7 @@ from sopel_modules.SpiceBot_SBTools import (
|
|||||||
sopel_triggerargs, inlist, channel_privs,
|
sopel_triggerargs, inlist, channel_privs,
|
||||||
join_all_channels, channel_list_current,
|
join_all_channels, channel_list_current,
|
||||||
)
|
)
|
||||||
|
from .Channels import bot_part_empty
|
||||||
|
|
||||||
|
|
||||||
@botevents.check_ready([botevents.BOT_LOADED])
|
@botevents.check_ready([botevents.BOT_LOADED])
|
||||||
@ -54,6 +55,7 @@ def nickname_comand_channels(bot, trigger):
|
|||||||
if not trigger.admin:
|
if not trigger.admin:
|
||||||
bot.osd("You do not have permission to update the channel listing.")
|
bot.osd("You do not have permission to update the channel listing.")
|
||||||
return
|
return
|
||||||
|
bot_part_empty(bot)
|
||||||
|
|
||||||
bot.write(['LIST'])
|
bot.write(['LIST'])
|
||||||
bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."])
|
bot.osd(["[SpiceBot_Channels]", "I am now updating the channel listing for this server."])
|
||||||
@ -63,7 +65,7 @@ def nickname_comand_channels(bot, trigger):
|
|||||||
join_all_channels(bot)
|
join_all_channels(bot)
|
||||||
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
foundchannelcount = len(bot.memory['SpiceBot_Channels']['channels'].keys())
|
||||||
bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.")
|
bot.osd("[SpiceBot_Channels]", "Channel listing finished!", str(foundchannelcount) + " channel(s) found.")
|
||||||
|
bot_part_empty(bot)
|
||||||
return
|
return
|
||||||
|
|
||||||
elif commandused == 'topic':
|
elif commandused == 'topic':
|
||||||
|
|||||||
@ -13,56 +13,144 @@ import os
|
|||||||
import spicemanip
|
import spicemanip
|
||||||
|
|
||||||
|
|
||||||
def configure(config):
|
# coding=utf8
|
||||||
config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False)
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
config.SpiceBot_Logs.configure_setting('logging_channel', 'SpiceBot_Logs channels')
|
|
||||||
|
__author__ = 'Sam Zick'
|
||||||
|
__email__ = 'sam@deathbybandaid.net'
|
||||||
|
__version__ = '0.1.1'
|
||||||
|
|
||||||
|
import sopel.module
|
||||||
|
import sopel.tools
|
||||||
|
import sopel.config
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
import spicemanip
|
||||||
|
|
||||||
|
|
||||||
class SpiceBot_Logs_MainSection(StaticSection):
|
class BotLogs():
|
||||||
logging_channel = ValidatedAttribute('logging_channel', default=False)
|
"""This Is a contained source of log information"""
|
||||||
|
def __init__(self):
|
||||||
|
self.SpiceBot_Logs = {
|
||||||
|
"list": {"Sopel_systemd": [], "Sopel_stdio": []},
|
||||||
|
"queue": []
|
||||||
|
}
|
||||||
|
self.sopel_config = {
|
||||||
|
"logging_channel": True
|
||||||
|
}
|
||||||
|
|
||||||
|
def log(self, logtype, logentry, stdio=False):
|
||||||
|
logtitle = "[" + logtype + "]"
|
||||||
|
logmessage = logtitle + " " + logentry
|
||||||
|
|
||||||
|
if self.sopel_config["logging_channel"]:
|
||||||
|
self.SpiceBot_Logs["queue"].append(logmessage)
|
||||||
|
|
||||||
|
if stdio:
|
||||||
|
sopel.tools.stderr(logmessage)
|
||||||
|
|
||||||
|
if logtype not in self.SpiceBot_Logs["list"].keys():
|
||||||
|
self.SpiceBot_Logs["list"][logtype] = []
|
||||||
|
self.SpiceBot_Logs["list"][logtype].append(logentry)
|
||||||
|
|
||||||
|
def get_logs(self):
|
||||||
|
return []
|
||||||
|
|
||||||
|
def stdio_logs_fetch(self, bot):
|
||||||
|
|
||||||
|
stdio_ignore = []
|
||||||
|
for logtype in botlogs.SpiceBot_Logs["list"].keys():
|
||||||
|
stdio_ignore.append("[" + logtype + "]")
|
||||||
|
|
||||||
|
logfile = os.path.os.path.join(bot.config.core.logdir, 'stdio.log')
|
||||||
|
|
||||||
|
try:
|
||||||
|
log_file_lines = []
|
||||||
|
log_file = open(logfile, 'r')
|
||||||
|
lines = log_file.readlines()
|
||||||
|
for line in lines:
|
||||||
|
log_file_lines.append(line)
|
||||||
|
log_file.close()
|
||||||
|
|
||||||
|
currentline, linenumindex = 0, []
|
||||||
|
for line in log_file_lines:
|
||||||
|
if line.startswith("Welcome to Sopel. Loading modules..."):
|
||||||
|
linenumindex.append(currentline)
|
||||||
|
currentline += 1
|
||||||
|
last_start = max(linenumindex)
|
||||||
|
filelines = log_file_lines[last_start:]
|
||||||
|
except Exception as e:
|
||||||
|
debuglines = e
|
||||||
|
filelines = []
|
||||||
|
|
||||||
|
debuglines = []
|
||||||
|
loadedmodules = []
|
||||||
|
for line in filelines:
|
||||||
|
if line.startswith("Loaded:"):
|
||||||
|
loadedmodules.append(str(line).split("Loaded:")[-1])
|
||||||
|
else:
|
||||||
|
if not line.startswith(tuple(stdio_ignore)) and not line.isspace():
|
||||||
|
debuglines.append(str(line))
|
||||||
|
loadedmodules = "Loaded: " + spicemanip.main(loadedmodules, 'andlist')
|
||||||
|
debuglines.insert(1, loadedmodules)
|
||||||
|
|
||||||
|
return debuglines
|
||||||
|
|
||||||
|
def systemd_logs_fetch(self, bot):
|
||||||
|
servicepid = self.get_running_pid(bot)
|
||||||
|
debuglines = []
|
||||||
|
for line in os.popen(str("sudo journalctl _PID=" + str(servicepid))).read().split('\n'):
|
||||||
|
line = str(line).split(str(os.uname()[1] + " "))[-1]
|
||||||
|
lineparts = str(line).split(": ")
|
||||||
|
del lineparts[0]
|
||||||
|
line = spicemanip.main(lineparts, 0)
|
||||||
|
if not line.isspace():
|
||||||
|
debuglines.append(str(line))
|
||||||
|
return debuglines
|
||||||
|
|
||||||
|
def get_running_pid(self, bot):
|
||||||
|
try:
|
||||||
|
filename = "/run/sopel/sopel-" + str(bot.nick) + ".pid"
|
||||||
|
with open(filename, 'r') as pid_file:
|
||||||
|
pidnum = int(pid_file.read())
|
||||||
|
except Exception as e:
|
||||||
|
pidnum = e
|
||||||
|
pidnum = str(os.popen("systemctl show " + str(bot.nick) + " --property=MainPID").read()).split("=")[-1]
|
||||||
|
return pidnum
|
||||||
|
|
||||||
|
|
||||||
|
botlogs = BotLogs()
|
||||||
|
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot_logging(bot, 'SpiceBot_Logs', "Starting Setup Procedure")
|
botlogs.log('SpiceBot_Logs', "Starting Setup Procedure")
|
||||||
bot.config.define_section("SpiceBot_Logs", SpiceBot_Logs_MainSection, validate=False)
|
|
||||||
|
|
||||||
botevents.startup_add([botevents.BOT_LOGS])
|
|
||||||
|
|
||||||
bot_logs_setup_check(bot)
|
|
||||||
|
|
||||||
botevents.trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs")
|
|
||||||
|
|
||||||
|
|
||||||
def bot_logs_setup_check(bot):
|
@sopel.module.event('001')
|
||||||
if 'SpiceBot_Logs' not in bot.memory:
|
|
||||||
bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": []}
|
|
||||||
|
|
||||||
|
|
||||||
def shutdown(bot):
|
|
||||||
if "SpiceBot_Logs" in bot.memory:
|
|
||||||
del bot.memory["SpiceBot_Logs"]
|
|
||||||
|
|
||||||
|
|
||||||
@sopel.module.event(botevents.BOT_CONNECTED)
|
|
||||||
@sopel.module.rule('.*')
|
@sopel.module.rule('.*')
|
||||||
def join_log_channel(bot, trigger):
|
def join_log_channel(bot, trigger):
|
||||||
|
|
||||||
if bot.config.SpiceBot_Logs.logging_channel:
|
if bot.config.core.logging_channel:
|
||||||
channel = bot.config.SpiceBot_Logs.logging_channel
|
channel = bot.config.core.logging_channel
|
||||||
if channel not in bot.channels.keys():
|
if channel not in bot.channels.keys():
|
||||||
bot.write(('JOIN', bot.nick, channel))
|
bot.write(('JOIN', bot.nick, channel))
|
||||||
if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin:
|
if channel not in bot.channels.keys() and bot.config.SpiceBot_Channels.operadmin:
|
||||||
bot.write(('SAJOIN', bot.nick, channel))
|
bot.write(('SAJOIN', bot.nick, channel))
|
||||||
|
|
||||||
bot_logs_setup_check(bot)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
if len(botlogs.SpiceBot_Logs["queue"]):
|
||||||
if len(bot.memory['SpiceBot_Logs']["queue"]):
|
bot.say(str(botlogs.SpiceBot_Logs["queue"][0]), channel)
|
||||||
bot.say(str(bot.memory['SpiceBot_Logs']["queue"][0]), channel)
|
del botlogs.SpiceBot_Logs["queue"][0]
|
||||||
del bot.memory['SpiceBot_Logs']["queue"][0]
|
else:
|
||||||
except KeyError:
|
botlogs.sopel_config["logging_channel"] = False
|
||||||
return
|
botlogs.SpiceBot_Logs["queue"] = []
|
||||||
|
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot_logging(bot, 'SpiceBot_Logs', "Starting Setup Procedure")
|
||||||
|
botevents.startup_add([botevents.BOT_LOGS])
|
||||||
|
botevents.trigger(bot, botevents.BOT_LOGS, "SpiceBot_Logs")
|
||||||
|
|
||||||
|
|
||||||
def stdio_logs_fetch(bot):
|
def stdio_logs_fetch(bot):
|
||||||
|
|||||||
@ -97,23 +97,8 @@ def command_permissions_check(bot, trigger, privslist):
|
|||||||
|
|
||||||
|
|
||||||
def bot_logging(bot, logtype, logentry, stdio=False):
|
def bot_logging(bot, logtype, logentry, stdio=False):
|
||||||
|
from sopel_modules.SpiceBot_Logs.Logs import botlogs
|
||||||
if 'SpiceBot_Logs' not in bot.memory:
|
botlogs.log(logtype, logentry, stdio=False)
|
||||||
bot.memory['SpiceBot_Logs'] = {"logs": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": []}
|
|
||||||
|
|
||||||
logmessage = "[" + logtype + "] " + logentry + ""
|
|
||||||
|
|
||||||
bot.memory['SpiceBot_Logs']["queue"].append(logmessage)
|
|
||||||
|
|
||||||
if stdio:
|
|
||||||
sopel.tools.stderr(logmessage)
|
|
||||||
|
|
||||||
if logtype not in bot.memory['SpiceBot_Logs']["logs"].keys():
|
|
||||||
bot.memory['SpiceBot_Logs']["logs"][logtype] = []
|
|
||||||
|
|
||||||
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]
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user