-
Notifications
You must be signed in to change notification settings - Fork 34
/
plugin_manager.py
120 lines (103 loc) · 4.84 KB
/
plugin_manager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# minqlx - A Quake Live server administrator bot.
# Copyright (C) 2015 Mino <[email protected]>
# This file is part of minqlx.
# minqlx is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# minqlx is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with minqlx. If not, see <http://www.gnu.org/licenses/>.
import minqlx
class plugin_manager(minqlx.Plugin):
def __init__(self):
self.add_command("load", self.cmd_load, 5, usage="<plugin>")
self.add_command("unload", self.cmd_unload, 5, usage="<plugin>")
self.add_command("reload", self.cmd_reload, 5, usage="<plugin>")
self.add_command("loadall", self.cmd_loadall, 5)
self.add_command("unloadall", self.cmd_unloadall, 5)
self.add_command("reloadall", self.cmd_reloadall, 5)
def cmd_load(self, player, msg, channel):
if len(msg) < 2:
return minqlx.RET_USAGE
else:
try:
minqlx.load_plugin(msg[1])
channel.reply("Plugin ^6{} ^7has been successfully loaded."
.format(msg[1]))
except Exception as e:
channel.reply("Plugin ^6{} ^7has failed to load: {} - {}"
.format(msg[1], e.__class__.__name__, e))
minqlx.log_exception(self)
def cmd_unload(self, player, msg, channel):
if len(msg) < 2:
return minqlx.RET_USAGE
else:
try:
minqlx.unload_plugin(msg[1])
channel.reply("Plugin ^6{} ^7has been successfully unloaded."
.format(msg[1]))
except Exception as e:
channel.reply("Plugin ^6{} ^7has failed to unload: {} - {}"
.format(msg[1], e.__class__.__name__, e))
minqlx.log_exception(self)
def cmd_reload(self, player, msg, channel):
if len(msg) < 2:
return minqlx.RET_USAGE
else:
# Wrap in next_frame to avoid the command going off several times due
# to the plugins dict being modified mid-command execution.
@minqlx.next_frame
def f():
try:
minqlx.reload_plugin(msg[1])
channel.reply("Plugin ^6{} ^7has been successfully reloaded."
.format(msg[1]))
except Exception as e:
channel.reply("Plugin ^6{} ^7has failed to reload: {} - {}"
.format(msg[1], e.__class__.__name__, e))
minqlx.log_exception(self)
f()
def cmd_loadall(self, player, msg, channel):
# Wrap in next_frame to avoid the command going off several times due
# to the plugins dict being modified mid-command execution.
@minqlx.next_frame
def f():
try:
minqlx.load_preset_plugins()
except Exception as e:
channel.reply("Plugins failed to load: {} - {}"
.format(e.__class__.__name__, e))
minqlx.log_exception(self)
channel.reply("Successfully loaded all plugins in ^6qlx_plugins^7.")
f()
def cmd_unloadall(self, player, msg, channel):
for plugin in self.plugins:
if plugin != self.__class__.__name__:
try:
minqlx.unload_plugin(plugin)
except Exception as e:
channel.reply("Plugin ^6{} ^7has failed to unload: {} - {}"
.format(plugin, e.__class__.__name__, e))
minqlx.log_exception(self)
channel.reply("Successfully unloaded all plugins except {}."
.format(self.__class__.__name__))
def cmd_reloadall(self, player, msg, channel):
# Wrap in next_frame to avoid the command going off several times due
# to the plugins dict being modified mid-command execution.
@minqlx.next_frame
def f():
for plugin in self.plugins:
if plugin != self.__class__.__name__:
try:
minqlx.reload_plugin(plugin)
except Exception as e:
channel.reply("Plugin ^6{} ^7has failed to unload: {} - {}"
.format(plugin, e.__class__.__name__, e))
minqlx.log_exception(self)
channel.reply("Successfully reloaded all plugins except {}."
.format(self.__class__.__name__))
f()