Merge pull request #21 from deathbybandaid/development

Development
This commit is contained in:
Deathbybandaid 2019-05-05 11:22:53 -04:00 committed by GitHub
commit 7f25c89c17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 139 additions and 23 deletions

View File

@ -6,6 +6,14 @@ SpiceBot aims to run SpiceBot as an IRC service
Use at your own risk. Problems are not my fault™.
# Installation
This install assumes you know that you need sopel installed, depending on how bleeding edge you want sopel to be,
````
pip3 install sopel>=6.0,<7
OR
pip3 install git+https://github.com/sopel-irc/sopel@master
````
````
git clone https://github.com/SpiceBot/SpiceBot.git
cd SpiceBot

View File

@ -1,4 +1,3 @@
sopel>=6.0,<7
spicemanip>=0.1.6
gitpython
fake-useragent

View File

@ -17,6 +17,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@sopel.module.nickname_commands('owners', 'owner')
def bot_command_owners(bot, trigger):
bot_command_process(bot, trigger)

View File

@ -20,6 +20,11 @@ def setup(bot):
threading.Thread(target=setup_thread, args=(bot,)).start()
def shutdown(bot):
if "Sopel_BotEvents" in bot.memory:
del bot.memory["Sopel_BotEvents"]
def setup_thread(bot):
if "Sopel_BotEvents" not in bot.memory:
bot.memory["Sopel_BotEvents"] = {"loaded": [], "startup": []}

View File

@ -51,6 +51,11 @@ def setup(bot):
bot.memory['SpiceBot_Channels']['ProcessLock'] = False
def shutdown(bot):
if "SpiceBot_Channels" in bot.memory:
del bot.memory["SpiceBot_Channels"]
@sopel.module.event('001')
@sopel.module.rule('.*')
def trigger_channel_list_initial(bot, trigger):
@ -132,7 +137,7 @@ def watch_chanlist_complete(bot, trigger):
@sopel.module.nickname_commands('channels', 'channel')
def nickname_comand_chanstats(bot, trigger):
def nickname_comand_channels(bot, trigger):
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')

View File

@ -26,6 +26,11 @@ def setup(bot):
threading.Thread(target=setup_thread, args=(bot,)).start()
def shutdown(bot):
if "SpiceBot_CommandsQuery" in bot.memory:
del bot.memory["SpiceBot_CommandsQuery"]
def setup_thread(bot):
if 'SpiceBot_CommandsQuery' not in bot.memory:

View File

@ -21,6 +21,10 @@ def setup(bot):
SopelDB._create_table = SopelDBCache._create_table
def shutdown(bot):
pass
class SopelDBCache:
"""Dynamic Table Creation"""

View File

@ -11,3 +11,8 @@ def setup(bot):
bot_logging(bot, 'SpiceBot_DatabaseCache', "Setting up Database Cache")
if 'SpiceBot_DatabaseCache' not in bot.memory:
bot.memory['SpiceBot_DatabaseCache'] = dict()
def shutdown(bot):
if "SpiceBot_DatabaseCache" in bot.memory:
del bot.memory["SpiceBot_DatabaseCache"]

View File

@ -6,6 +6,18 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
import sopel.module
def configure(config):
pass
def setup(bot):
pass
def shutdown(bot):
pass
"""Dyanmic Table Creation"""

View File

@ -17,6 +17,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@sopel.module.nickname_commands('help', 'docs', 'wiki')
def bot_command_owners(bot, trigger):
bot.osd(["IRC Modules Repository", str(github_dict["url_main"] + github_dict["repo_owner"] + "/" + github_dict["repo_name"] + github_dict["url_path_wiki"])])

View File

@ -15,6 +15,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@sopel.module.rule(r'(?i)(hi|hello|hey),? $nickname[ \t]*$')
def bot_command_hello(bot, trigger):
hello = spicemanip.main(['Hi', 'Hey', 'Hello'], "random")

View File

@ -13,6 +13,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@sopel.module.nickname_commands('gender')
def bot_command_gender(bot, trigger):
bot.osd("If societal genders are binary, my gender is female")

View File

@ -57,6 +57,11 @@ def setup(bot):
threading.Thread(target=setup_thread, args=(bot,)).start()
def shutdown(bot):
if "SpiceBot_GifSearch" in bot.memory:
del bot.memory["SpiceBot_GifSearch"]
def setup_thread(bot):
startup_bot_event(bot, "SpiceBot_GifSearch")

View File

@ -13,6 +13,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@sopel.module.rule(r'(?i)(Fuck|Screw) (you|off),? $nickname[ \t]*$')
def bot_command_srewyou(bot, trigger):
bot.osd("Watch your mouth, " + trigger.nick + ", or I'll tell your mother!")

View File

@ -30,6 +30,13 @@ def setup(bot):
bot.memory['SpiceBot_Logs_queue'] = []
def shutdown(bot):
if "SpiceBot_Logs" in bot.memory:
del bot.memory["SpiceBot_Logs"]
if "SpiceBot_Logs_queue" in bot.memory:
del bot.memory["SpiceBot_Logs_queue"]
@sopel.module.event('001')
@sopel.module.rule('.*')
def join_log_channel(bot, trigger):

View File

@ -17,6 +17,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@sopel.module.nickname_commands('action')
def bot_command_action(bot, trigger):
bot_command_process(bot, trigger)

View File

@ -6,16 +6,22 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
import sopel.module
from sopel.config.types import StaticSection, ValidatedAttribute
from sopel_modules.SpiceBot_SBTools import service_manip, bot_logging
from sopel_modules.SpiceBot_SBTools import service_manip, bot_logging, spicebot_reload
def shutdown(bot):
pass
@sopel.module.nickname_commands('restart')
def nickname_comand_chanstats(bot, trigger):
def nickname_comand_restart(bot, trigger):
if not trigger.admin:
bot.say("You are not authorized to perform this function.")
bot_logging(bot, 'SpiceBot_Restart', "Received command from " + trigger.nick + " to restart")
bot.osd("Received command from " + trigger.nick + " to restart. Be Back Soon!", bot.channels.keys())
quitmessage = "Received command from " + trigger.nick + " to restart. Be Back Soon!"
bot_logging(bot, 'SpiceBot_Restart', quitmessage)
bot.osd(quitmessage, bot.channels.keys())
service_manip(bot, bot.nick, 'restart', 'SpiceBot_Restart')
# service_manip(bot, bot.nick, 'restart', 'SpiceBot_Restart')
spicebot_reload(bot, 'SpiceBot_Restart', quitmessage)

View File

@ -97,8 +97,7 @@ def bot_logging(bot, logtype, logentry):
logmessage = "[" + logtype + "] " + logentry + ""
if bot.config.SpiceBot_Logs.logging_channel:
bot.memory['SpiceBot_Logs_queue'].append(logmessage)
bot.memory['SpiceBot_Logs_queue'].append(logmessage)
stderr("\n" + logmessage + "\n")
@ -252,6 +251,13 @@ def channel_list_current(bot):
"""Environment Functions"""
def spicebot_reload(bot, log_from='service_manip', quitmessage='Recieved QUIT'):
# service_manip(bot, bot.nick, 'restart', log_from)
# bot.reload_plugins()
# bot.write(('NOTICE', bot.nick), '001 Foo :Hello')
bot.restart(quitmessage)
def service_manip(bot, servicename, dowhat, log_from='service_manip'):
if str(dowhat) not in ["start", "stop", "restart"]:
return

View File

@ -18,6 +18,10 @@ def setup(bot):
pass
def shutdown(bot):
pass
@module.event('001')
@module.rule('.*')
@module.thread(True)

View File

@ -7,10 +7,11 @@ import sopel.module
from sopel.config.types import StaticSection, ValidatedAttribute
import os
import pip
import spicemanip
from sopel_modules.SpiceBot_SBTools import service_manip, sopel_triggerargs, command_permissions_check, bot_logging
from sopel_modules.SpiceBot_SBTools import service_manip, sopel_triggerargs, command_permissions_check, bot_logging, spicebot_reload
class SpiceBot_Update_MainSection(StaticSection):
@ -29,8 +30,12 @@ def setup(bot):
bot.config.define_section("SpiceBot_Update", SpiceBot_Update_MainSection, validate=False)
def shutdown(bot):
pass
@sopel.module.nickname_commands('update')
def nickname_comand_chanstats(bot, trigger):
def nickname_comand_update(bot, trigger):
if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
bot.say("I was unable to process this Bot Nick command due to privilege issues.")
@ -49,21 +54,23 @@ def nickname_comand_chanstats(bot, trigger):
triggerargs = spicemanip.main(triggerargs, '2+', 'list')
bot_logging(bot, 'SpiceBot_Update', "Received command from " + trigger.nick + " to update from Github and restart")
bot.osd("Received command from " + trigger.nick + " to update from Github and restart. Be Back Soon!", bot.channels.keys())
quitmessage = "Received command from " + trigger.nick + " to update from Github and restart"
bot_logging(bot, 'SpiceBot_Update', quitmessage)
bot.osd(quitmessage, bot.channels.keys())
if commandused == 'nodeps':
spicebot_update(bot, "False")
spicebot_update(bot, False)
if commandused == 'deps':
spicebot_update(bot, "True")
spicebot_update(bot, True)
service_manip(bot, bot.nick, 'restart', 'SpiceBot_Update')
# service_manip(bot, bot.nick, 'restart', 'SpiceBot_Update')
spicebot_reload(bot, 'SpiceBot_Update', quitmessage)
def spicebot_update(bot, deps="False"):
def spicebot_update(bot, deps=False):
pipcommand = "sudo pip3 install --upgrade"
if deps == "False":
if not deps:
pipcommand += " --no-deps"
pipcommand += " --force-reinstall"
pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch)
@ -72,6 +79,11 @@ def spicebot_update(bot, deps="False"):
for line in os.popen(pipcommand).read().split('\n'):
bot_logging(bot, 'SpiceBot_Update', " " + line)
stock_modules_begone(bot)
def stock_modules_begone(bot):
# Remove stock modules, if present
main_sopel_dir = os.path.dirname(os.path.abspath(sopel.__file__))
modules_dir = os.path.join(main_sopel_dir, 'modules')

View File

@ -22,6 +22,11 @@ def setup(bot):
bot.memory["SpiceBot_Uptime"] = now
def shutdown(bot):
if "SpiceBot_Uptime" in bot.memory:
del bot.memory["SpiceBot_Uptime"]
@sopel.module.nickname_commands('uptime')
def bot_command_srewyou(bot, trigger):
timesince = str(humanized_time(time.time() - bot.memory["SpiceBot_Uptime"])) + " ago."

View File

@ -37,23 +37,27 @@ def setup(bot):
# Inject OSD
bot_logging(bot, 'SpiceBot_OSD', "Implanting OSD function into bot")
bot.osd = SopelOSD.osd
bot.SopelWrapper.osd = SopelOSD.SopelWrapper.osd
sopel.bot.SopelWrapper.osd = SopelOSD.SopelWrapper.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
# overwrite default bot messaging
bot_logging(bot, 'SpiceBot_OSD', "Overwrite Default Sopel messaging commands")
bot.SopelWrapper.say = SopelOSD.SopelWrapper.say
bot.SopelWrapper.action = SopelOSD.SopelWrapper.action
bot.SopelWrapper.notice = SopelOSD.SopelWrapper.notice
bot.SopelWrapper.reply = SopelOSD.SopelWrapper.reply
sopel.bot.SopelWrapper.say = SopelOSD.SopelWrapper.say
sopel.bot.SopelWrapper.action = SopelOSD.SopelWrapper.action
sopel.bot.SopelWrapper.notice = SopelOSD.SopelWrapper.notice
sopel.bot.SopelWrapper.reply = SopelOSD.SopelWrapper.reply
# verify config settings for server
bot_logging(bot, 'SpiceBot_OSD', "Checking for config settings")
bot.config.define_section("MAXTARGCONFIG", MAXTARGCONFIG, validate=False)
def shutdown(bot):
pass
# RPL_ISUPPORT = '005'
@module.event('005')
@module.rule('.*')