Skip to content

Commit 5287d81

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/cleanup'
2 parents 3b0d290 + d884489 commit 5287d81

File tree

4 files changed

+115
-64
lines changed

4 files changed

+115
-64
lines changed

motobot/core_plugins/disable_module.py

+69-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
@request('GET_PLUGINS')
55
def disabled_request(bot, context, channel):
6-
disabled = context.database.get({}).get(channel.lower(), set())
6+
disabled = context.database.get({}).get(channel.lower(), [])
77
return filter_plugins(bot.plugins, disabled)
88

99

@@ -15,7 +15,31 @@ def filter_plugins(plugins, disabled):
1515
)
1616

1717

18-
@command('module', priority=Priority.max, level=IRCLevel.op)
18+
def get_modules(bot):
19+
return [module for module in bot.modules if not module.startswith('motobot.core_plugins')]
20+
21+
22+
def user_module_command(bot, context, message, args):
23+
try:
24+
arg = args[1].lower()
25+
26+
if arg == ('enable', 'disable', 'show'):
27+
response = "Error: You do not have the privileges to use this argument."
28+
elif arg == 'list':
29+
module = ' '.join(args[2:])
30+
response = list_module(get_modules(bot), module)
31+
elif arg == 'get':
32+
module = ' '.join(args[2:])
33+
response = get_module(get_modules(bot), module)
34+
else:
35+
response = "Error: Invalid argument."
36+
except IndexError:
37+
response = "Error: Too few arguments supplied."
38+
39+
return response, Notice(context.nick)
40+
41+
42+
@command('module', priority=Priority.max, level=IRCLevel.op, alt=user_module_command)
1943
def module_command(bot, context, message, args):
2044
""" Command to enable or disable modules in the bot.
2145
@@ -33,15 +57,15 @@ def module_command(bot, context, message, args):
3357
response = enable_module(context.database, context.channel, module)
3458
elif arg == 'disable':
3559
module = ' '.join(args[2:])
36-
response = disable_module(bot, context.database, context.channel, module)
60+
response = disable_module(get_modules(bot), context.database, context.channel, module)
3761
elif arg == 'show':
3862
response = show_disabled_modules(context.database, context.channel)
3963
elif arg == 'list':
4064
module = ' '.join(args[2:])
41-
response = list_module(bot, module)
65+
response = list_module(get_modules(bot), module)
4266
elif arg == 'get':
4367
module = ' '.join(args[2:])
44-
response = get_module(bot, module)
68+
response = get_module(get_modules(bot), module)
4569
else:
4670
response = "Error: Invalid argument."
4771
except IndexError:
@@ -51,25 +75,57 @@ def module_command(bot, context, message, args):
5175

5276

5377
def enable_module(database, channel, module):
54-
return "Error: Not yet implemented."
78+
channel = channel.lower()
79+
disabled_modules = database.get({})
80+
disabled_channel_modules = disabled_modules.get(channel, [])
5581

82+
try:
83+
disabled_channel_modules.remove(module)
84+
disabled_modules[channel] = disabled_channel_modules
85+
database.set(disabled_modules)
86+
response = "{} is now enabled in {}.".format(module, channel)
87+
except ValueError:
88+
response = "{} was not disabled in {}.".format(module, channel)
89+
return response
5690

57-
def disable_module(bot, database, channel, module):
58-
return "Error: Not yet implemented."
91+
92+
def disable_module(modules, database, channel, module):
93+
if module in modules:
94+
channel = channel.lower()
95+
disabled_modules = database.get({})
96+
disabled_channel_modules = disabled_modules.get(channel, [])
97+
98+
if module in disabled_channel_modules:
99+
response = "{} is already disabled in {}.".format(module, channel)
100+
else:
101+
disabled_channel_modules.append(module)
102+
disabled_modules[channel] = disabled_channel_modules
103+
database.set(disabled_modules)
104+
response = "{} successfully disabled in {}.".format(module, channel)
105+
else:
106+
response = "{} is not a valid module.".format(module)
107+
108+
return response
59109

60110

61111
def show_disabled_modules(database, channel):
62-
return "Error: Not yet implemented."
112+
disabled_channel_modules = database.get({}).get(channel.lower(), [])
113+
if disabled_channel_modules:
114+
response = split_response(disabled_channel_modules,
115+
"Disabled modules in {}: {};".format(channel, '{}'))
116+
else:
117+
response = "I have no modules disabled in {}.".format(channel)
118+
return response
63119

64120

65-
def list_module(bot, module):
121+
def list_module(modules, module):
66122
if module:
67-
pass
123+
response = None # TODO
68124
else:
69-
response = split_response(bot.modules, "Modules: {};")
125+
response = split_response(modules, "Modules: {};")
70126

71127
return response
72128

73129

74-
def get_module(bot, module):
130+
def get_module(modules, module):
75131
return "Error: Not yet implemented."

motobot/core_plugins/ignore.py

+44-30
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,71 @@
1-
from motobot import command, sink, Priority, IRCLevel, Eat, Notice, split_response
1+
from motobot import command, sink, Priority, IRCLevel, Eat, Notice, split_response, hostmask_check
22

33

44
@command('ignore', priority=Priority.max, level=IRCLevel.hop)
55
def ignore_command(bot, context, message, args):
6-
""" Manage ignores in a channel.
7-
8-
Valid arguments are: 'add', 'del', 'all, and 'show'.
9-
'add' and 'del' require a nick argument.
10-
'all' will toggle ignoring for the entire channel on and off.
11-
'show' will show the currently ignored nicks in the channel.
12-
"""
13-
response = ''
6+
""" Ignore a nick or host mask in the current channel. """
147
try:
15-
arg = args[1].lower()
16-
if arg == 'add':
17-
response = add_ignore(context.database, context.channel, args[2])
18-
elif arg == 'del' or arg == 'rem':
19-
response = del_ignore(context.database, context.channel, args[2])
20-
elif arg == 'all':
21-
response = ignoreall(context.channel)
22-
elif arg == 'show':
23-
response = show_ignores(context.database, context.channel)
24-
else:
25-
response = 'Error: Invalid argument;'
8+
response = add_ignore(context.database, context.channel, args[1])
269
except IndexError:
27-
response = "Not enough arguments provided."
10+
response = "Error: Please provide a mask or nick to ignore."
2811
return response, Notice(context.nick)
2912

3013

14+
@command('unignore', priority=Priority.max, level=IRCLevel.hop)
15+
def unignore_command(bot, context, message, args):
16+
""" Unignore a nick or host mask in the current channel. """
17+
try:
18+
response = del_ignore(context.database, context.channel, args[1])
19+
except IndexError:
20+
response = "Error: Please provide a mask or nick to unignore."
21+
return response, Notice(context.nick)
22+
23+
24+
@command('ignorelist', priority=Priority.max, level=IRCLevel.hop)
25+
def ignorelist_command(bot, context, message, args):
26+
""" List the ignored host masks in the current channel. """
27+
return show_ignores(context.database, context.channel), Notice(context.nick)
28+
29+
30+
@command('ignoreall', priority=Priority.max, level=IRCLevel.hop)
31+
def ignoreall_command(bot, context, message, args):
32+
""" Toggle on or off ignoring everyone in the current channel. """
33+
return ignoreall(context.channel)
34+
35+
36+
def nick_to_mask(mask):
37+
if '!' not in mask and '@' not in mask:
38+
mask += '!*@*'
39+
return mask.lower()
40+
41+
3142
def add_ignore(database, channel, nick):
3243
ignores = database.get({})
3344
channel_ignores = ignores.get(channel, [])
45+
mask = nick_to_mask(nick)
3446

35-
if nick.lower() in channel_ignores:
47+
if mask in channel_ignores:
3648
response = "I'm already ignoring {} on {}.".format(nick, channel)
3749
else:
38-
channel_ignores.append(nick.lower())
50+
channel_ignores.append(mask)
3951
ignores[channel] = channel_ignores
4052
database.set(ignores)
41-
response = "I'm now ignoring {} on {}.".format(nick, channel)
53+
response = "I'm now ignoring {} on {}.".format(mask, channel)
4254
return response
4355

4456

4557
def del_ignore(database, channel, nick):
4658
ignores = database.get({})
4759
channel_ignores = ignores.get(channel, [])
60+
mask = nick_to_mask(nick)
4861

4962
try:
50-
channel_ignores.remove(nick.lower())
63+
channel_ignores.remove(mask)
5164
ignores[channel] = channel_ignores
5265
database.set(ignores)
53-
response = "I'm no longer ignoring {} on {}.".format(nick, channel)
54-
except KeyError:
55-
response = "I'm not ignoring {} on {}.".format(nick, channel)
66+
response = "I'm no longer ignoring {} on {}.".format(mask, channel)
67+
except ValueError:
68+
response = "I'm not ignoring {} on {}.".format(mask, channel)
5669
return response
5770

5871

@@ -85,8 +98,9 @@ def ignoreall(channel):
8598

8699
def ignore_sink(bot, context, message):
87100
channel_ignores = context.database.get({}).get(context.channel, [])
88-
if context.nick.lower() in channel_ignores:
89-
return Eat
101+
for mask in channel_ignores:
102+
if hostmask_check(context.nick, context.host, mask):
103+
return Eat
90104

91105

92106
@sink(priority=Priority.max, level=IRCLevel.hop, alt=ignore_sink)

motobot/core_plugins/master_verification.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33

44
@request('IS_MASTER')
5-
def is_master_request(bot, context, nick, host=None):
5+
def is_master_request(bot, context, nick, host):
66
recognised = context.session.get(set())
77
admin_masks = context.database.get([])
88
return nick.lower() in recognised or \

motobot/core_plugins/userlist_handlers.py

+1-20
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,6 @@
11
from motobot import hook, request, command, IRCLevel, Notice
22

33

4-
@command('levelprobe')
5-
def levelprobe_command(bot, context, message, args):
6-
try:
7-
nick = args[1]
8-
mapping = {
9-
IRCLevel.user: "Regular User",
10-
IRCLevel.voice: "Voice",
11-
IRCLevel.hop: "Half-op",
12-
IRCLevel.aop: "Op",
13-
IRCLevel.sop: "Protected Op",
14-
IRCLevel.owner: "Owner",
15-
IRCLevel.master: "Bot Admin",
16-
}
17-
level = bot.request('USERLEVEL', context.channel, nick)
18-
return "{} is a {} ({}) on {}.".format(nick, mapping.get(level, "Unknown"), level, context.channel)
19-
except IndexError:
20-
return "Please provide a nick argument.", Notice(context.nick)
21-
22-
234
@request('USERLIST')
245
def userlist_request(bot, context, channel):
256
return [x[1] for x in context.session.get({}) if x[0].lower() == channel.lower()]
@@ -29,7 +10,7 @@ def userlist_request(bot, context, channel):
2910
def userlevel_request(bot, context, channel, nick, host=None):
3011
userlevel_data = context.session.get({})
3112
level = IRCLevel.user
32-
if bot.request('IS_MASTER', nick, host):
13+
if host is not None and bot.request('IS_MASTER', nick, host):
3314
level = IRCLevel.master
3415
elif channel.lower() == bot.nick.lower():
3516
level = IRCLevel.owner

0 commit comments

Comments
 (0)