This commit is contained in:
deathbybandaid 2019-05-31 13:39:50 -04:00
parent 9ddcc55ab2
commit 263f61cd8e
6 changed files with 64 additions and 69 deletions

View File

@ -10,6 +10,7 @@ from .configure import *
from .setup import *
from .Update import *
from .osd import *
from .Config import *
from .Tools import *

View File

@ -4,10 +4,20 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
from .Channels import SpiceBot_Channels_MainSection
from .Update import SpiceBot_Update_MainSection
from .osd import SpiceBot_OSD
def configure(config):
config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
config.SpiceBot_OSD.configure_setting('notice', 'MAXTARG limit for NOTICE')
config.SpiceBot_OSD.configure_setting('privmsg', 'MAXTARG limit for PRIVMSG')
config.SpiceBot_OSD.configure_setting('flood_burst_lines', 'How many messages can be sent in burst mode.')
config.SpiceBot_OSD.configure_setting('flood_empty_wait', 'How long to wait between sending messages when not in burst mode, in seconds.')
config.SpiceBot_OSD.configure_setting('flood_refill_rate', 'How quickly burst mode recovers, in messages per second.')
config.SpiceBot_OSD.configure_setting('flood_throttle', 'Whether messages will be throttled if too many are sent in a short time.')
config.SpiceBot_OSD.configure_setting('flood_dots', "Whether repeated messages will be replaced with '...', then dropped.")
config.define_section("SpiceBot_Channels", SpiceBot_Channels_MainSection, validate=False)
config.SpiceBot_Channels.configure_setting('announcenew', 'SpiceBot_Channels Announce New Channels')
config.SpiceBot_Channels.configure_setting('joinall', 'SpiceBot_Channels JOIN New Channels')

View File

@ -1,83 +1,18 @@
# coding=utf8
"""Sopel OSD
Sopel OSD is a "niche" method of displaying text in a Sopel bot
from __future__ import unicode_literals, absolute_import, division, print_function
"""
This is the SpiceBot OSD system.
"""
# pylama:ignore=W0611
from __future__ import unicode_literals, absolute_import, division, print_function
import sopel.bot
from sopel import tools, module
from sopel import tools
from sopel.tools import Identifier
from sopel.config.types import StaticSection, ValidatedAttribute
import sopel_modules.SpiceBot as SpiceBot
import time
from collections import abc
import sys
__author__ = 'Sam Zick'
__email__ = 'sam@deathbybandaid.net'
__version__ = '0.1.2'
def configure(config):
config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
config.SpiceBot_OSD.configure_setting('notice', 'MAXTARG limit for NOTICE')
config.SpiceBot_OSD.configure_setting('privmsg', 'MAXTARG limit for PRIVMSG')
config.SpiceBot_OSD.configure_setting('flood_burst_lines', 'How many messages can be sent in burst mode.')
config.SpiceBot_OSD.configure_setting('flood_empty_wait', 'How long to wait between sending messages when not in burst mode, in seconds.')
config.SpiceBot_OSD.configure_setting('flood_refill_rate', 'How quickly burst mode recovers, in messages per second.')
config.SpiceBot_OSD.configure_setting('flood_throttle', 'Whether messages will be throttled if too many are sent in a short time.')
config.SpiceBot_OSD.configure_setting('flood_dots', "Whether repeated messages will be replaced with '...', then dropped.")
def setup(bot):
# Inject OSD
SpiceBot.logs.log('SpiceBot_OSD', "Implanting OSD function into bot")
bot.osd = SopelOSD.osd
sopel.bot.SopelWrapper.osd = SopelWrapperOSD.osd
tools.get_available_message_bytes = ToolsOSD.get_available_message_bytes
tools.get_sendable_message_list = ToolsOSD.get_sendable_message_list
tools.get_message_recipientgroups = ToolsOSD.get_message_recipientgroups
# verify config settings for server
SpiceBot.logs.log('SpiceBot_OSD', "Checking for config settings")
bot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
SpiceBot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
@module.event('005')
@module.rule('.*')
def parse_event_005(bot, trigger):
if trigger.args[-1] != 'are supported by this server':
return
parameters = trigger.args[1:-1]
for param in parameters:
if '=' in param:
if param.startswith("TARGMAX"):
param = str(param).split('=')[1]
settings = str(param).split(',')
for setting in settings:
settingname = str(setting).split(':')[0]
if settingname.upper() in ['NOTICE', 'PRIVMSG']:
try:
value = str(setting).split(':')[1] or None
except IndexError:
value = None
if value:
if settingname.upper() == 'NOTICE':
bot.config.SpiceBot_OSD.notice = int(value)
elif settingname.upper() == 'PRIVMSG':
bot.config.SpiceBot_OSD.privmsg = int(value)
class SpiceBot_OSD(StaticSection):
"""MAXTARG"""

View File

@ -2,6 +2,9 @@
from __future__ import unicode_literals, absolute_import, division, print_function
"""Setup for SpiceBot"""
import sopel.bot
from sopel import tools
import os
from .Config import config as botconfig
@ -9,10 +12,24 @@ from .Logs import logs
from .Channels import SpiceBot_Channels_MainSection
from .Update import SpiceBot_Update_MainSection
from .osd import SopelWrapperOSD, ToolsOSD, SopelOSD, SpiceBot_OSD
def setup(bot):
# Inject OSD
logs.log('SpiceBot_OSD', "Implanting OSD function into bot")
bot.osd = SopelOSD.osd
sopel.bot.SopelWrapper.osd = SopelWrapperOSD.osd
tools.get_available_message_bytes = ToolsOSD.get_available_message_bytes
tools.get_sendable_message_list = ToolsOSD.get_sendable_message_list
tools.get_message_recipientgroups = ToolsOSD.get_message_recipientgroups
# verify config settings for server
logs.log('SpiceBot_OSD', "Checking for config settings")
bot.config.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
botconfig.define_section("SpiceBot_OSD", SpiceBot_OSD, validate=False)
logs.log('SpiceBot_Config', "Setting Up Configuration")
bot.config.core.basename = os.path.basename(bot.config.filename).rsplit('.', 1)[0]
bot.config.core.logs_stdio = os.path.join(bot.config.core.logdir, 'stdio.log')

View File

@ -9,6 +9,7 @@ This module contains references only for other modules to utilize.
from .Channels import *
from .Events import *
from .Modules import *
from .osd import *
__author__ = 'Sam Zick'

View File

@ -0,0 +1,31 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
"""
This is the SpiceBot OSD system.
"""
import sopel
@sopel.module.event('005')
@sopel.module.rule('.*')
def parse_event_005(bot, trigger):
if trigger.args[-1] != 'are supported by this server':
return
parameters = trigger.args[1:-1]
for param in parameters:
if '=' in param:
if param.startswith("TARGMAX"):
param = str(param).split('=')[1]
settings = str(param).split(',')
for setting in settings:
settingname = str(setting).split(':')[0]
if settingname.upper() in ['NOTICE', 'PRIVMSG']:
try:
value = str(setting).split(':')[1] or None
except IndexError:
value = None
if value:
if settingname.upper() == 'NOTICE':
bot.config.SpiceBot_OSD.notice = int(value)
elif settingname.upper() == 'PRIVMSG':
bot.config.SpiceBot_OSD.privmsg = int(value)