mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
Merge pull request #7 from SpiceBot/development
Channels/Tools: Sopel tracks chan privs. Simply list() them.
This commit is contained in:
commit
6f6317992a
@ -194,12 +194,12 @@ def nickname_comand_chanstats(bot, trigger):
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||
return
|
||||
channel_privs(bot, channel)
|
||||
privlist = channel_privs(bot, channel, commandused.upper())
|
||||
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))
|
||||
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)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
@ -213,12 +213,12 @@ def nickname_comand_chanstats(bot, trigger):
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||
return
|
||||
channel_privs(bot, channel)
|
||||
privlist = channel_privs(bot, channel, commandused.upper())
|
||||
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))
|
||||
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)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
@ -232,12 +232,12 @@ def nickname_comand_chanstats(bot, trigger):
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||
return
|
||||
channel_privs(bot, channel)
|
||||
privlist = channel_privs(bot, channel, commandused.upper())
|
||||
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))
|
||||
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)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
@ -251,12 +251,12 @@ def nickname_comand_chanstats(bot, trigger):
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||
return
|
||||
channel_privs(bot, channel)
|
||||
privlist = channel_privs(bot, channel, commandused.upper())
|
||||
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))
|
||||
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)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
@ -270,12 +270,12 @@ def nickname_comand_chanstats(bot, trigger):
|
||||
if not inlist(bot, channel.lower(), bot.channels.keys()):
|
||||
bot.osd("I need to be in {} to see nick privileges.".format(channel))
|
||||
return
|
||||
channel_privs(bot, channel)
|
||||
privlist = channel_privs(bot, channel, commandused.upper())
|
||||
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))
|
||||
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)
|
||||
bot.osd(dispmsg, trigger.nick, 'notice')
|
||||
return
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
"""
|
||||
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
|
||||
HOP = HALFOP
|
||||
@ -65,32 +66,18 @@ def topic_compile(topic):
|
||||
return topic
|
||||
|
||||
|
||||
def channel_privs(bot, channel):
|
||||
|
||||
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] = []
|
||||
|
||||
def channel_privs(bot, channel, privtype):
|
||||
privlist = []
|
||||
for user in bot.channels[channel].privileges.keys():
|
||||
try:
|
||||
privnum = bot.channels[channel].privileges[user] or 0
|
||||
except KeyError:
|
||||
privnum = 0
|
||||
|
||||
for privtype in ['VOICE', 'HOP', 'OP', 'ADMIN', 'OWNER']:
|
||||
if privnum == eval(privtype) or (privnum >= eval(privtype) and privtype == 'OWNER'):
|
||||
if user not in bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype]:
|
||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype].append(user)
|
||||
else:
|
||||
if user in bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype]:
|
||||
bot.memory['SpiceBot_Channels']['channels'][str(channel).lower()][privtype].remove(user)
|
||||
if (privnum == eval(privtype) or
|
||||
(privnum >= eval(privtype) and privtype == 'OWNER') or
|
||||
(privnum >= eval(privtype) and privnum < eval("OWNER") and privtype == 'ADMIN')):
|
||||
privlist.append(user)
|
||||
return privlist
|
||||
|
||||
|
||||
def join_all_channels(bot):
|
||||
@ -109,7 +96,6 @@ def chanadmin_all_channels(bot):
|
||||
if bot.config.SpiceBot_Channels.operadmin:
|
||||
if not bot.channels[channel].privileges[bot.nick] < ADMIN:
|
||||
bot.write(('SAMODE', channel, "+a", bot.nick))
|
||||
channel_privs(bot, channel)
|
||||
else:
|
||||
bot.part(channel)
|
||||
|
||||
@ -140,12 +126,25 @@ def service_manip(bot, servicename, dowhat):
|
||||
stderr(str(dowhat).title() + "ing " + str(servicename) + ".service Failed: " + str(e))
|
||||
|
||||
|
||||
def spicebot_update(bot):
|
||||
try:
|
||||
stderr("Updating " + bot.nick + " from Github.")
|
||||
for line in os.popen("pip3 install --upgrade --force-reinstall git+" +
|
||||
str(bot.config.SpiceBot_Update.gitrepo) +
|
||||
"@" + str(bot.config.SpiceBot_Update.gitbranch)).read().split('\n'):
|
||||
stderr(line)
|
||||
except Exception as e:
|
||||
stderr("Updating " + bot.nick + " from Github Failed:" + str(e))
|
||||
def spicebot_update(bot, deps="False"):
|
||||
stderr("Updating " + bot.nick + " from Github.")
|
||||
|
||||
pipcommand = "sudo pip3 install --upgrade"
|
||||
if deps == "False":
|
||||
pipcommand += " --no-deps"
|
||||
pipcommand += " --force-reinstall"
|
||||
pipcommand += " git+" + str(bot.config.SpiceBot_Update.gitrepo) + "@" + str(bot.config.SpiceBot_Update.gitbranch)
|
||||
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
|
||||
|
||||
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):
|
||||
gitrepo = ValidatedAttribute('gitrepo', default="https://github.com/SpiceBot/SpiceBot")
|
||||
gitbranch = ValidatedAttribute('gitrepo', default="master")
|
||||
gitbranch = ValidatedAttribute('gitbranch', default="master")
|
||||
|
||||
|
||||
def configure(config):
|
||||
@ -31,12 +33,28 @@ def setup(bot):
|
||||
@sopel.module.nickname_commands('update')
|
||||
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:
|
||||
bot.say("You are not authorized to perform this function.")
|
||||
|
||||
stderr("Recieved Command to update.")
|
||||
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')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user