mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-11 06:00:59 -05:00
Code Cleanup
This commit is contained in:
parent
cd1b8d88a8
commit
717766217c
@ -5,9 +5,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
import sopel.module
|
||||
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
|
||||
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event, startup_bot_event
|
||||
|
||||
@ -44,6 +42,8 @@ def shutdown(bot):
|
||||
@sopel.module.event('1004')
|
||||
@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():
|
||||
|
||||
@ -4,12 +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
|
||||
from sopel import coretasks, config
|
||||
from sopel.trigger import PreTrigger, Trigger
|
||||
from sopel.bot import SopelWrapper
|
||||
HOP = HALFOP
|
||||
|
||||
import collections
|
||||
import re
|
||||
@ -102,7 +96,7 @@ def bot_logging(bot, logtype, logentry):
|
||||
|
||||
bot.memory['SpiceBot_Logs']["queue"].append(logmessage)
|
||||
|
||||
stderr("\n" + logmessage + "\n")
|
||||
sopel.tools.stderr("\n" + logmessage + "\n")
|
||||
|
||||
if logtype not in bot.memory['SpiceBot_Logs']["logs"].keys():
|
||||
bot.memory['SpiceBot_Logs']["logs"][logtype] = []
|
||||
@ -208,9 +202,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 +227,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)
|
||||
|
||||
@ -4,10 +4,8 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
||||
|
||||
import sopel.module
|
||||
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_recieved, bot_events_trigger
|
||||
from sopel_modules.SpiceBot_LoadOrder.LoadOrder import set_bot_event
|
||||
from sopel_modules.SpiceBot_SBTools import humanized_time, bot_logging
|
||||
import time
|
||||
from sopel_modules.SpiceBot_Events.System import bot_events_recieved
|
||||
from sopel_modules.SpiceBot_SBTools import bot_logging
|
||||
|
||||
|
||||
def setup(bot):
|
||||
@ -17,55 +15,6 @@ def setup(bot):
|
||||
bot.memory['SpiceBot_StartupMonologue'] = []
|
||||
|
||||
|
||||
@sopel.module.event('1003')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_start(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')
|
||||
|
||||
bot.memory['SpiceBot_StartupMonologue'].append(bot.nick + " startup complete")
|
||||
|
||||
|
||||
@sopel.module.event('2002')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_commands(bot, trigger):
|
||||
|
||||
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.")
|
||||
|
||||
|
||||
@sopel.module.event('2001')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_channels(bot, trigger):
|
||||
|
||||
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.")
|
||||
|
||||
|
||||
@sopel.module.event('1004')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_startup_monologue_display(bot, trigger):
|
||||
|
||||
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.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys())
|
||||
|
||||
set_bot_event(bot, "SpiceBot_StartupMonologue")
|
||||
bot_events_trigger(bot, 2005, "SpiceBot_StartupMonologue")
|
||||
|
||||
|
||||
@sopel.module.event('2005')
|
||||
@sopel.module.rule('.*')
|
||||
def bot_events_setup(bot, trigger):
|
||||
|
||||
@ -0,0 +1,63 @@
|
||||
# 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_LoadOrder.LoadOrder import set_bot_event
|
||||
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.")
|
||||
|
||||
|
||||
@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.")
|
||||
|
||||
|
||||
@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.osd(bot.memory['SpiceBot_StartupMonologue'], bot.channels.keys())
|
||||
|
||||
set_bot_event(bot, "SpiceBot_StartupMonologue")
|
||||
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'
|
||||
|
||||
Loading…
Reference in New Issue
Block a user