This commit is contained in:
deathbybandaid 2022-06-29 12:32:48 -04:00
parent d2205d01c2
commit fb5c0a88ed
3 changed files with 164 additions and 6 deletions

View File

@ -6,12 +6,16 @@ from .database import Database
from .comms import Comms
from .events import Events
from .commands import Commands
from .users import Users
class SpiceBotCore_OBJ():
def __init__(self, script_dir):
# Setup sopel bot access for later
self.bot = None
# Set directory for the plugin
self.script_dir = script_dir
@ -40,9 +44,13 @@ class SpiceBotCore_OBJ():
self.logger.info("SpiceBot Comms Interface Setup Complete.")
# SpiceBots access to Sopel Command listing
self.commands = Commands(self.config)
self.commands = Commands(self.config, self.bot)
self.logger.info("SpiceBot Commands Interface Setup Complete.")
# SpiceBots access to Sopel Command listing
self.users = Users(self.bot)
self.logger.info("SpiceBot Users Interface Setup Complete.")
def setup(self, bot):
"""This runs with the plugin setup routine"""
@ -52,9 +60,6 @@ class SpiceBotCore_OBJ():
# Re-initialize the bot config properly during plugin setup routine
self.config.config = bot.config
# Give Spicebot access to bot commands
self.commands.bot = bot
# OSD shortcut
def osd(self, messages, recipients=None, text_method='PRIVMSG', max_messages=-1):
return self.comms.osd(messages, recipients, text_method, max_messages)

View File

@ -7,8 +7,8 @@ from sopel.trigger import PreTrigger
class Commands():
def __init__(self, config):
self.bot = None
def __init__(self, config, bot):
self.bot = bot
self.config = config
@property

View File

@ -0,0 +1,153 @@
from sopel import plugin
class Users():
def __init__(self, bot):
self.bot = None
"""Bot Priviledges"""
def has_bot_privilege(self, nick, channelstr, privilege):
if privilege == "ADMIN":
if nick in self.is_bot_admin():
return True
elif nick in self.is_bot_owner():
return True
elif privilege == "OWNER":
if nick in self.is_bot_owner():
return True
return False
"""Bot Owner"""
def list_bot_owner(self):
list_owner = self.bot.config.owner
if not isinstance(list_owner, list):
list_owner = [list_owner]
return list_owner
def is_bot_owner(self, nick):
if nick in self.list_bot_owner():
return True
return False
"""Bot Admins"""
def list_bot_admin(self):
list_admins = self.bot.config.admins
if not isinstance(list_admins, list):
list_admins = [list_admins]
return list_admins
def is_bot_admin(self, user):
if user in self.list_bot_admin():
return True
return False
"""Channel Users"""
def list_channel_users(self, channelstr):
channel = self.bot.channels[channelstr]
return list(channel.users.items())
def is_channel_user(self, channelstr, user):
if user in self.list_channel_users(channelstr):
return True
return False
"""Channel Priviledges"""
def has_channel_privilege(self, nick, channelstr, privilege):
if privilege.upper() == "OPER":
privilege = plugin.OPER
elif privilege.upper() == "OWNER":
privilege = plugin.OWNER
elif privilege == "ADMIN":
privilege = plugin.ADMIN
elif privilege.upper() == "OP":
privilege = plugin.OP
elif privilege.upper() in ["HALFOP", "HOP"]:
privilege = plugin.HALFOP
elif privilege.upper() == "VOICE":
privilege = plugin.VOICE
else:
return False
channel = self.bot.channels[channelstr]
if nick in [user for nick, user in channel.users if channel.has_privileges(nick, privilege)]:
return True
return False
"""Channel OPER"""
def list_channel_users_oper(self, channelstr):
channel = self.bot.channels[channelstr]
return [user for nick, user in channel.users if channel.is_oper(nick, plugin.OPER)]
def is_channel_oper(self, channelstr, user):
if user in self.list_channel_users_oper(channelstr):
return True
return False
"""Channel OWNER Users"""
def list_channel_users_owner(self, channelstr):
channel = self.bot.channels[channelstr]
return [user for nick, user in channel.users if channel.is_owner(nick, plugin.OWNER)]
def is_channel_owner(self, channelstr, user):
if user in self.list_channel_users_owner(channelstr):
return True
return False
"""Channel ADMIN Users"""
def list_channel_users_admin(self, channelstr):
channel = self.bot.channels[channelstr]
return [user for nick, user in channel.users if channel.is_admin(nick, plugin.ADMIN)]
def is_channel_admin(self, channelstr, user):
if user in self.list_channel_users_admin(channelstr):
return True
return False
"""Channel OP Users"""
def list_channel_users_op(self, channelstr):
channel = self.bot.channels[channelstr]
return [user for nick, user in channel.users if channel.is_op(nick, plugin.OP)]
def is_channel_op(self, channelstr, user):
if user in self.list_channel_users_op(channelstr):
return True
return False
"""Channel HALFOP Users"""
def list_channel_users_halfop(self, channelstr):
channel = self.bot.channels[channelstr]
return [user for nick, user in channel.users if channel.is_halfop(nick, plugin.HALFOP)]
def is_channel_halfop(self, channelstr, user):
if user in self.list_channel_users_halfop(channelstr):
return True
return False
"""Channel VOICE Users"""
def list_channel_users_voice(self, channelstr):
channel = self.bot.channels[channelstr]
return [user for nick, user in channel.users if channel.is_voice(nick, plugin.VOICE)]
def is_channel_voice(self, channelstr, user):
if user in self.list_channel_users_voice(channelstr):
return True
return False