-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpluginlib.py
85 lines (75 loc) · 2.98 KB
/
pluginlib.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
#!/usr/bin/env python3
# Developed by Rafik Mas'ad (Azag).
# PluginLib 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
# any later version.
#
# PluginLib 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 this program. If not, see <http://www.gnu.org/licenses/
import irclib
import imp
class main:
def __init__(self, plugin_list, irc):
for plugin in plugin_list:
exec("from plugins import {0}".format(plugin))
exec("self.{0}_module = {0}".format(plugin))
exec("self.{0} = {0}.main(irc)".format(plugin))
self.plugin_list = plugin_list
self.irc = irc
self.do = irclib.commands(irc)
def signal(self, msg_data, bot_data):
if msg_data["nick"].lower() in bot_data["ops"]:
#RESTART
if msg_data["msg"][:9] == "@restart ":
module = msg_data["msg"][9:]
receiver = msg_data["receiver"]
try:
exec("imp.reload(self.{0}_module)".format(module))
exec("self.{0} = self.{0}_module.main(self.irc)".format(module))
self.do.send(receiver, "{0} restarted".format(module))
except:
self.do.send(receiver, "{0} is not already started".format(module))
try:
exec("from plugins import {0}".format(module))
exec("self.{0}_module = {0}".format(plugin))
exec("self.{0} = {0}.main(irc)".format(plugin))
self.do.send(receiver, "{0} started".format(module))
if module not in self.plugin_list:
self.plugin_list += [module]
except:
self.do.send(receiver, "{0} don't exist".format(module))
#START
if msg_data["msg"][:7] == "@start ":
module = msg_data["msg"][7:]
receiver = msg_data["receiver"]
try:
exec("imp.reload(self.{0}_module)".format(module))
exec("self.{0} = self.{0}_module.main(self.irc)".format(module))
self.do.send(receiver, "{0} already started".format(module))
except:
try:
exec("from plugins import {0}".format(module))
exec("self.{0}_module = {0}".format(plugin))
exec("self.{0} = {0}.main(irc)".format(plugin))
self.do.send(receiver, "{0} started".format(module))
if module not in self.plugin_list:
self.plugin_list += [module]
except:
self.do.send(receiver, "{0} don't exist".format(module))
#STOP
if msg_data["msg"][:6] == "@stop ":
module = msg_data["msg"][6:]
receiver = msg_data["receiver"]
if module in self.plugin_list:
del(self.plugin_list[self.plugin_list.index(module)])
self.do.send(receiver, "{0} stoped".format(module))
else:
self.do.send(receiver, "{0} is not already started".format(module))
for plugin in self.plugin_list:
exec("self.{0}.main(msg_data, bot_data)".format(plugin))