mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 22:49:53 -05:00
Channels/Tools: Sopel tracks chan privs. Simply list() them.
This commit is contained in:
parent
bf9d769d89
commit
fef01bdd06
@ -194,12 +194,12 @@ def nickname_comand_chanstats(bot, trigger):
|
|||||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||||
return
|
return
|
||||||
channel_privs(bot, channel)
|
privlist = channel_privs(bot, channel, commandused.upper())
|
||||||
dispmsg = []
|
dispmsg = []
|
||||||
if not len(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()]):
|
if not len(privlist):
|
||||||
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
||||||
else:
|
else:
|
||||||
oplist = spicemanip.main(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()], 'andlist')
|
oplist = spicemanip.main(privlist, 'andlist')
|
||||||
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
||||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||||
return
|
return
|
||||||
@ -213,12 +213,12 @@ def nickname_comand_chanstats(bot, trigger):
|
|||||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||||
return
|
return
|
||||||
channel_privs(bot, channel)
|
privlist = channel_privs(bot, channel, commandused.upper())
|
||||||
dispmsg = []
|
dispmsg = []
|
||||||
if not len(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()]):
|
if not len(privlist):
|
||||||
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
||||||
else:
|
else:
|
||||||
oplist = spicemanip.main(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()], 'andlist')
|
oplist = spicemanip.main(privlist, 'andlist')
|
||||||
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
||||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||||
return
|
return
|
||||||
@ -232,12 +232,12 @@ def nickname_comand_chanstats(bot, trigger):
|
|||||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||||
return
|
return
|
||||||
channel_privs(bot, channel)
|
privlist = channel_privs(bot, channel, commandused.upper())
|
||||||
dispmsg = []
|
dispmsg = []
|
||||||
if not len(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()]):
|
if not len(privlist):
|
||||||
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
||||||
else:
|
else:
|
||||||
oplist = spicemanip.main(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()], 'andlist')
|
oplist = spicemanip.main(privlist, 'andlist')
|
||||||
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
||||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||||
return
|
return
|
||||||
@ -251,12 +251,12 @@ def nickname_comand_chanstats(bot, trigger):
|
|||||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||||
return
|
return
|
||||||
channel_privs(bot, channel)
|
privlist = channel_privs(bot, channel, commandused.upper())
|
||||||
dispmsg = []
|
dispmsg = []
|
||||||
if not len(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()]):
|
if not len(privlist):
|
||||||
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
||||||
else:
|
else:
|
||||||
oplist = spicemanip.main(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()], 'andlist')
|
oplist = spicemanip.main(privlist, 'andlist')
|
||||||
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
||||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||||
return
|
return
|
||||||
@ -270,12 +270,12 @@ def nickname_comand_chanstats(bot, trigger):
|
|||||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||||
return
|
return
|
||||||
channel_privs(bot, channel)
|
privlist = channel_privs(bot, channel, commandused.upper())
|
||||||
dispmsg = []
|
dispmsg = []
|
||||||
if not len(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()]):
|
if not len(privlist):
|
||||||
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
dispmsg.append("There are no Channel " + commandused.upper() + "s for " + str(channel))
|
||||||
else:
|
else:
|
||||||
oplist = spicemanip.main(bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][commandused.upper()], 'andlist')
|
oplist = spicemanip.main(privlist, 'andlist')
|
||||||
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
dispmsg.append("Channel " + commandused.upper() + "s for " + str(channel) + " are: " + oplist)
|
||||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||||
return
|
return
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals, absolute_import, print_function, division
|
from __future__ import unicode_literals, absolute_import, print_function, division
|
||||||
|
|
||||||
|
import sopel
|
||||||
from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP
|
from sopel.module import OP, ADMIN, VOICE, OWNER, HALFOP
|
||||||
from sopel.tools import stderr
|
from sopel.tools import stderr
|
||||||
HOP = HALFOP
|
HOP = HALFOP
|
||||||
@ -65,32 +66,18 @@ def topic_compile(topic):
|
|||||||
return topic
|
return topic
|
||||||
|
|
||||||
|
|
||||||
def channel_privs(bot, channel):
|
def channel_privs(bot, channel, privtype):
|
||||||
|
privlist = []
|
||||||
if channel not in bot.memory['SpiceBot_Channels']['channels'].keys():
|
|
||||||
topic = bot.channels[channel].topic
|
|
||||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()] = dict()
|
|
||||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()]['name'] = str(channel)
|
|
||||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()]['topic'] = topic_compile(topic)
|
|
||||||
|
|
||||||
for chan in bot.memory['SpiceBot_Channels']['channels'].keys():
|
|
||||||
for privtype in ['VOICE', 'HOP', 'OP', 'ADMIN', 'OWNER']:
|
|
||||||
if privtype not in bot.memory['SpiceBot_Channels']['channels'][str(chan).lower()].keys():
|
|
||||||
bot.memory['SpiceBot_Channels']['channels'][str(chan).lower()][privtype] = []
|
|
||||||
|
|
||||||
for user in bot.channels[channel].privileges.keys():
|
for user in bot.channels[channel].privileges.keys():
|
||||||
try:
|
try:
|
||||||
privnum = bot.channels[channel].privileges[user] or 0
|
privnum = bot.channels[channel].privileges[user] or 0
|
||||||
except KeyError:
|
except KeyError:
|
||||||
privnum = 0
|
privnum = 0
|
||||||
|
if (privnum == eval(privtype) or
|
||||||
for privtype in ['VOICE', 'HOP', 'OP', 'ADMIN', 'OWNER']:
|
(privnum >= eval(privtype) and privtype == 'OWNER') or
|
||||||
if privnum == eval(privtype) or (privnum >= eval(privtype) and privtype == 'OWNER'):
|
(privnum >= eval(privtype) and privnum < eval("OWNER") and privtype == 'ADMIN')):
|
||||||
if user not in bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype]:
|
privlist.append(user)
|
||||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype].append(user)
|
return privlist
|
||||||
else:
|
|
||||||
if user in bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype]:
|
|
||||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype].remove(user)
|
|
||||||
|
|
||||||
|
|
||||||
def join_all_channels(bot):
|
def join_all_channels(bot):
|
||||||
@ -109,7 +96,6 @@ def chanadmin_all_channels(bot):
|
|||||||
if bot.config.SpiceBot_Channels.operadmin:
|
if bot.config.SpiceBot_Channels.operadmin:
|
||||||
if not bot.channels[channel].privileges[bot.nick] < ADMIN:
|
if not bot.channels[channel].privileges[bot.nick] < ADMIN:
|
||||||
bot.write(('SAMODE', channel, "+a", bot.nick))
|
bot.write(('SAMODE', channel, "+a", bot.nick))
|
||||||
channel_privs(bot, channel)
|
|
||||||
else:
|
else:
|
||||||
bot.part(channel)
|
bot.part(channel)
|
||||||
|
|
||||||
@ -140,12 +126,25 @@ def service_manip(bot, servicename, dowhat):
|
|||||||
stderr(str(dowhat).title() + "ing " + str(servicename) + ".service Failed: " + str(e))
|
stderr(str(dowhat).title() + "ing " + str(servicename) + ".service Failed: " + str(e))
|
||||||
|
|
||||||
|
|
||||||
def spicebot_update(bot):
|
def spicebot_update(bot, deps="False"):
|
||||||
try:
|
stderr("Updating " + bot.nick + " from Github.")
|
||||||
stderr("Updating " + bot.nick + " from Github.")
|
|
||||||
for line in os.popen("pip3 install --upgrade --force-reinstall git+" +
|
pipcommand = "sudo pip3 install --upgrade"
|
||||||
str(bot.config.SpiceBot_Update.gitrepo) +
|
if deps == "False":
|
||||||
"@" + str(bot.config.SpiceBot_Update.gitbranch)).read().split('\n'):
|
pipcommand += " --no-deps"
|
||||||
stderr(line)
|
pipcommand += " --force-reinstall"
|
||||||
except Exception as e:
|
pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch)
|
||||||
stderr("Updating " + bot.nick + " from Github Failed:" + str(e))
|
stderr(pipcommand)
|
||||||
|
for line in os.popen(pipcommand).read().split('\n'):
|
||||||
|
stderr(line)
|
||||||
|
|
||||||
|
# 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')
|
||||||
|
stockdir = os.path.join(modules_dir, "stock")
|
||||||
|
if not os.path.exists(stockdir) or not os.path.isdir(stockdir):
|
||||||
|
os.system("sudo mkdir " + stockdir)
|
||||||
|
for pathname in os.listdir(modules_dir):
|
||||||
|
path = os.path.join(modules_dir, pathname)
|
||||||
|
if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')):
|
||||||
|
os.system("sudo mv " + path + " " + stockdir)
|
||||||
|
|||||||
@ -9,12 +9,14 @@ from sopel.config.types import StaticSection, ValidatedAttribute
|
|||||||
|
|
||||||
import sopel_modules.osd
|
import sopel_modules.osd
|
||||||
|
|
||||||
from sopel_modules.SpiceBot_SBTools import service_manip, spicebot_update
|
import spicemanip
|
||||||
|
|
||||||
|
from sopel_modules.SpiceBot_SBTools import service_manip, spicebot_update, sopel_triggerargs
|
||||||
|
|
||||||
|
|
||||||
class SpiceBot_Update_MainSection(StaticSection):
|
class SpiceBot_Update_MainSection(StaticSection):
|
||||||
gitrepo = ValidatedAttribute('gitrepo', default="https://github.com/SpiceBot/SpiceBot")
|
gitrepo = ValidatedAttribute('gitrepo', default="https://github.com/SpiceBot/SpiceBot")
|
||||||
gitbranch = ValidatedAttribute('gitrepo', default="master")
|
gitbranch = ValidatedAttribute('gitbranch', default="master")
|
||||||
|
|
||||||
|
|
||||||
def configure(config):
|
def configure(config):
|
||||||
@ -31,12 +33,28 @@ def setup(bot):
|
|||||||
@sopel.module.nickname_commands('update')
|
@sopel.module.nickname_commands('update')
|
||||||
def nickname_comand_chanstats(bot, trigger):
|
def nickname_comand_chanstats(bot, trigger):
|
||||||
|
|
||||||
|
triggerargs = sopel_triggerargs(bot, trigger, 'nickname_command')
|
||||||
|
|
||||||
|
if not len(triggerargs):
|
||||||
|
commandused = 'nodeps'
|
||||||
|
else:
|
||||||
|
commandused = spicemanip.main(triggerargs, 1).lower()
|
||||||
|
|
||||||
|
if commandused not in ['deps', 'nodeps']:
|
||||||
|
bot.say("Please specify deps or nodeps")
|
||||||
|
return
|
||||||
|
|
||||||
|
triggerargs = spicemanip.main(triggerargs, '2+', 'list')
|
||||||
|
|
||||||
if not trigger.admin:
|
if not trigger.admin:
|
||||||
bot.say("You are not authorized to perform this function.")
|
bot.say("You are not authorized to perform this function.")
|
||||||
|
|
||||||
stderr("Recieved Command to update.")
|
stderr("Recieved Command to update.")
|
||||||
bot.osd("Received command from " + trigger.nick + " to update from Github and restart. Be Back Soon!", bot.channels.keys())
|
bot.osd("Received command from " + trigger.nick + " to update from Github and restart. Be Back Soon!", bot.channels.keys())
|
||||||
|
|
||||||
spicebot_update(bot)
|
if commandused == 'nodeps':
|
||||||
|
spicebot_update(bot, "False")
|
||||||
|
if commandused == 'deps':
|
||||||
|
spicebot_update(bot, "True")
|
||||||
|
|
||||||
service_manip(bot, bot.nick, 'restart')
|
service_manip(bot, bot.nick, 'restart')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user