Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
ed782e9
admin: check output consistency
Exirel Sep 11, 2020
df67359
adminchannel: check output consistency
Exirel Sep 11, 2020
0141509
announce: check output consistency
Exirel Sep 11, 2020
eea3e4a
bugzilla: proper config import
Exirel Sep 14, 2020
9279381
calc: check output consistency
Exirel Sep 11, 2020
1c689d1
choose: check output consistency
Exirel Sep 11, 2020
9d7d8ee
clock: check output consistency
Exirel Sep 11, 2020
48e3f30
countdown: check output consistency
Exirel Sep 11, 2020
652c6bd
currency: check output consistency
Exirel Sep 11, 2020
0c9d5af
dice: check output consistency
Exirel Sep 11, 2020
ab0cac7
emoticons: check output consistency
Exirel Sep 11, 2020
efa2798
find: check output consistency
Exirel Sep 11, 2020
f7695ab
find_updates: check output consistency
Exirel Sep 11, 2020
4d299d1
help: replace sopel.module by sopel.plugin
Exirel Sep 12, 2020
c92eba9
instagram: check output consistency
Exirel Sep 12, 2020
e213bd5
invite: check output consistency
Exirel Sep 12, 2020
8b6318f
ip: check output consistency
Exirel Sep 12, 2020
98e33ee
isup: check output consistency
Exirel Sep 12, 2020
a7e4390
lmgtfy: check output consistency
Exirel Sep 12, 2020
855f98a
meetbot: proper imports
Exirel Sep 14, 2020
ec8629f
ping: replace sopel.module by sopel.plugin
Exirel Sep 12, 2020
595d807
pronouns: check output consistency
Exirel Sep 12, 2020
72da978
py: check output consistency
Exirel Sep 12, 2020
8b0e497
rand: check output consistency
Exirel Sep 12, 2020
fa9516a
reddit: check output consistency
Exirel Sep 12, 2020
67e5656
reload: check output consistency
Exirel Sep 12, 2020
9094e8b
remind: check output consistency
Exirel Sep 12, 2020
5f9e014
safety: check output consistency
Exirel Sep 12, 2020
e7ad8ba
search: check output consistency
Exirel Sep 12, 2020
3d9a540
seen: check output consistency
Exirel Sep 12, 2020
b71fa31
tell: check output consistency
Exirel Sep 12, 2020
b71063e
tld: check output consistency
Exirel Sep 12, 2020
aae4c81
translate: check output consistency
Exirel Sep 12, 2020
0e5ee11
unicode_info: check output consistency
Exirel Sep 12, 2020
e875c63
units: check output consistency
Exirel Sep 12, 2020
f156e8c
uptime: check output consistency
Exirel Sep 12, 2020
278ad8e
url: check output consistency
Exirel Sep 12, 2020
4188154
version: check output consistency
Exirel Sep 12, 2020
85535b0
wikipedia: check output consistency
Exirel Sep 12, 2020
eb02803
wiktionary: check output consistency
Exirel Sep 12, 2020
ce5cf44
xkcd: check output consistency
Exirel Sep 12, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 74 additions & 76 deletions sopel/modules/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
"""
from __future__ import absolute_import, division, print_function, unicode_literals

from sopel.config.types import (
FilenameAttribute, StaticSection, ValidatedAttribute
)
import sopel.module
from sopel import plugin
from sopel.config import types


class AdminSection(StaticSection):
hold_ground = ValidatedAttribute('hold_ground', bool, default=False)
class AdminSection(types.StaticSection):
hold_ground = types.ValidatedAttribute('hold_ground', bool, default=False)
"""Auto re-join on kick"""
auto_accept_invite = ValidatedAttribute('auto_accept_invite', bool,
default=True)
auto_accept_invite = types.ValidatedAttribute('auto_accept_invite', bool,
default=True)
"""Auto-join channels when invited"""


Expand Down Expand Up @@ -101,24 +99,24 @@ def _part(bot, channel, msg=None, save=True):
_set_config_channels(bot, channels)


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('join')
@sopel.module.priority('low')
@sopel.module.example('.join #example key', user_help=True)
@sopel.module.example('.join #example', user_help=True)
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('join')
@plugin.priority('low')
@plugin.example('.join #example key', user_help=True)
@plugin.example('.join #example', user_help=True)
def join(bot, trigger):
"""Join the specified channel. This is an admin-only command."""
channel, key = trigger.group(3), trigger.group(4)
_join(bot, channel, key)


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('tmpjoin')
@sopel.module.priority('low')
@sopel.module.example('.tmpjoin #example key', user_help=True)
@sopel.module.example('.tmpjoin #example', user_help=True)
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('tmpjoin')
@plugin.priority('low')
@plugin.example('.tmpjoin #example key', user_help=True)
@plugin.example('.tmpjoin #example', user_help=True)
def temporary_join(bot, trigger):
"""Like ``join``, without saving. This is an admin-only command.

Expand All @@ -129,22 +127,22 @@ def temporary_join(bot, trigger):
_join(bot, channel, key, save=False)


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('part')
@sopel.module.priority('low')
@sopel.module.example('.part #example')
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('part')
@plugin.priority('low')
@plugin.example('.part #example')
def part(bot, trigger):
"""Part the specified channel. This is an admin-only command."""
channel, _sep, part_msg = trigger.group(2).partition(' ')
_part(bot, channel, part_msg)


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('tmppart')
@sopel.module.priority('low')
@sopel.module.example('.tmppart #example')
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('tmppart')
@plugin.priority('low')
@plugin.example('.tmppart #example')
def temporary_part(bot, trigger):
"""Like ``part``, without saving. This is an admin-only command.

Expand All @@ -155,10 +153,10 @@ def temporary_part(bot, trigger):
_part(bot, channel, part_msg, save=False)


@sopel.module.require_privmsg
@sopel.module.require_owner
@sopel.module.commands('restart')
@sopel.module.priority('low')
@plugin.require_privmsg
@plugin.require_owner
@plugin.command('restart')
@plugin.priority('low')
def restart(bot, trigger):
"""Restart the bot. This is an owner-only command."""
quit_message = trigger.group(2)
Expand All @@ -168,10 +166,10 @@ def restart(bot, trigger):
bot.restart(quit_message)


@sopel.module.require_privmsg
@sopel.module.require_owner
@sopel.module.commands('quit')
@sopel.module.priority('low')
@plugin.require_privmsg
@plugin.require_owner
@plugin.command('quit')
@plugin.priority('low')
def quit(bot, trigger):
"""Quit from the server. This is an owner-only command."""
quit_message = trigger.group(2)
Expand All @@ -181,11 +179,11 @@ def quit(bot, trigger):
bot.quit(quit_message)


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('say', 'msg')
@sopel.module.priority('low')
@sopel.module.example('.say #YourPants Does anyone else smell neurotoxin?')
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('say', 'msg')
@plugin.priority('low')
@plugin.example('.say #YourPants Does anyone else smell neurotoxin?')
def say(bot, trigger):
"""
Send a message to a given channel or nick. Can only be done in privmsg by
Expand All @@ -202,10 +200,10 @@ def say(bot, trigger):
bot.say(message, channel)


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('me')
@sopel.module.priority('low')
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('me')
@plugin.priority('low')
def me(bot, trigger):
"""
Send an ACTION (/me) to a given channel or nick. Can only be done in
Expand All @@ -222,17 +220,17 @@ def me(bot, trigger):
bot.action(action, channel)


@sopel.module.event('INVITE')
@sopel.module.priority('low')
@plugin.event('INVITE')
@plugin.priority('low')
def invite_join(bot, trigger):
"""Join a channel Sopel is invited to, if the inviter is an admin."""
if trigger.admin or bot.config.admin.auto_accept_invite:
bot.join(trigger.args[1])
return


@sopel.module.event('KICK')
@sopel.module.priority('low')
@plugin.event('KICK')
@plugin.priority('low')
def hold_ground(bot, trigger):
"""
This function monitors all kicks across all channels Sopel is in. If it
Expand All @@ -245,10 +243,10 @@ def hold_ground(bot, trigger):
bot.join(trigger.sender)


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('mode')
@sopel.module.priority('low')
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('mode')
@plugin.priority('low')
def mode(bot, trigger):
"""Set a user mode on Sopel. Can only be done in privmsg by an admin."""
mode = trigger.group(3)
Expand Down Expand Up @@ -282,7 +280,7 @@ def parse_section_option_value(config, trigger):
section = getattr(config, section_name, False)
if not section:
raise InvalidSection(section_name)
static_sec = isinstance(section, StaticSection)
static_sec = isinstance(section, types.StaticSection)

if static_sec and not hasattr(section, option):
raise InvalidSectionOption(section_name, option) # Option not found in section
Expand All @@ -302,10 +300,10 @@ def parse_section_option_value(config, trigger):
return (section, section_name, static_sec, option, value)


@sopel.module.require_privmsg("This command only works as a private message.")
@sopel.module.require_admin("This command requires admin privileges.")
@sopel.module.commands('set')
@sopel.module.example('.set core.owner MyNick')
@plugin.require_privmsg("This command only works as a private message.")
@plugin.require_admin("This command requires admin privileges.")
@plugin.command('set')
@plugin.example('.set core.owner MyNick')
def set_config(bot, trigger):
"""See and modify values of Sopel's config object.

Expand All @@ -319,7 +317,7 @@ def set_config(bot, trigger):
try:
section, section_name, static_sec, option, value = parse_section_option_value(bot.config, trigger)
except ValueError:
bot.reply('Usage: {}set section.option [value]'.format(bot.config.core.help_prefix))
bot.say('Usage: {}set section.option [value]'.format(bot.config.core.help_prefix))
return
except (InvalidSection, InvalidSectionOption) as exc:
bot.say(exc.args[1])
Expand All @@ -341,7 +339,7 @@ def set_config(bot, trigger):
# TODO: consider a deprecation warning when loading settings
value = "(password censored)"

bot.reply("%s.%s = %s (%s)" % (section_name, option, value, type(value).__name__))
bot.say("%s.%s = %s (%s)" % (section_name, option, value, type(value).__name__))
return

# Owner-related settings cannot be modified interactively. Any changes to these
Expand All @@ -354,7 +352,7 @@ def set_config(bot, trigger):
# Otherwise, set the value to one given
if descriptor is not None:
try:
if isinstance(descriptor, FilenameAttribute):
if isinstance(descriptor, types.FilenameAttribute):
value = descriptor.parse(value, bot.config, descriptor)
else:
value = descriptor.parse(value)
Expand All @@ -365,10 +363,10 @@ def set_config(bot, trigger):
bot.say("OK. Set '{}.{}' successfully.".format(section_name, option))


@sopel.module.require_privmsg("This command only works as a private message.")
@sopel.module.require_admin("This command requires admin privileges.")
@sopel.module.commands('unset')
@sopel.module.example('.unset core.owner')
@plugin.require_privmsg("This command only works as a private message.")
@plugin.require_admin("This command requires admin privileges.")
@plugin.command('unset')
@plugin.example('.unset core.owner')
def unset_config(bot, trigger):
"""Unset value of Sopel's config object.

Expand All @@ -383,28 +381,28 @@ def unset_config(bot, trigger):
try:
section, section_name, static_sec, option, value = parse_section_option_value(bot.config, trigger)
except ValueError:
bot.reply('Usage: {}unset section.option [value]'.format(bot.config.core.help_prefix))
bot.say('Usage: {}unset section.option [value]'.format(bot.config.core.help_prefix))
return
except (InvalidSection, InvalidSectionOption) as exc:
bot.say(exc.args[1])
return

if value:
bot.reply('Invalid command; no value should be provided to unset.')
bot.say('Invalid command; no value should be provided to unset.')
return

try:
setattr(section, option, None)
bot.say("OK. Unset '{}.{}' successfully.".format(section_name, option))
bot.say("Unset '{}.{}' successfully.".format(section_name, option))
except ValueError:
bot.reply('Cannot unset {}.{}; it is a required option.'.format(section_name, option))
bot.say('Cannot unset {}.{}; it is a required option.'.format(section_name, option))


@sopel.module.require_privmsg
@sopel.module.require_admin
@sopel.module.commands('save')
@sopel.module.example('.save')
@plugin.require_privmsg
@plugin.require_admin
@plugin.command('save')
@plugin.example('.save')
def save_config(bot, trigger):
"""Save state of Sopel's config object to the configuration file."""
bot.config.save()
bot.reply('Configuration file saved.')
bot.say('Configuration file saved.')
Loading