3
3
4
4
@request ('GET_PLUGINS' )
5
5
def disabled_request (bot , context , channel ):
6
- disabled = context .database .get ({}).get (channel .lower (), set () )
6
+ disabled = context .database .get ({}).get (channel .lower (), [] )
7
7
return filter_plugins (bot .plugins , disabled )
8
8
9
9
@@ -15,7 +15,31 @@ def filter_plugins(plugins, disabled):
15
15
)
16
16
17
17
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 )
19
43
def module_command (bot , context , message , args ):
20
44
""" Command to enable or disable modules in the bot.
21
45
@@ -33,15 +57,15 @@ def module_command(bot, context, message, args):
33
57
response = enable_module (context .database , context .channel , module )
34
58
elif arg == 'disable' :
35
59
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 )
37
61
elif arg == 'show' :
38
62
response = show_disabled_modules (context .database , context .channel )
39
63
elif arg == 'list' :
40
64
module = ' ' .join (args [2 :])
41
- response = list_module (bot , module )
65
+ response = list_module (get_modules ( bot ) , module )
42
66
elif arg == 'get' :
43
67
module = ' ' .join (args [2 :])
44
- response = get_module (bot , module )
68
+ response = get_module (get_modules ( bot ) , module )
45
69
else :
46
70
response = "Error: Invalid argument."
47
71
except IndexError :
@@ -51,25 +75,57 @@ def module_command(bot, context, message, args):
51
75
52
76
53
77
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 , [])
55
81
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
56
90
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
59
109
60
110
61
111
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
63
119
64
120
65
- def list_module (bot , module ):
121
+ def list_module (modules , module ):
66
122
if module :
67
- pass
123
+ response = None # TODO
68
124
else :
69
- response = split_response (bot . modules , "Modules: {};" )
125
+ response = split_response (modules , "Modules: {};" )
70
126
71
127
return response
72
128
73
129
74
- def get_module (bot , module ):
130
+ def get_module (modules , module ):
75
131
return "Error: Not yet implemented."
0 commit comments