This repository has been archived by the owner on Apr 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin_system.py
64 lines (47 loc) · 1.56 KB
/
plugin_system.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
# -*- coding: utf-8 -*-
from enum import Enum
import config
from rate_limit import RATE_GLOBAL
class ptypes(Enum):
PARSE = 1
COMMAND = 2
MUC_ONLINE = 3
plugin_storage = {ptype: [] for ptype in ptypes}
def pluginfunction(name, desc, plugin_type, ratelimit_class=RATE_GLOBAL, enabled=True):
"""A decorator to make a plugin out of a function
:param enabled:
:param ratelimit_class:
:param plugin_type:
:param desc:
:param name:
"""
def decorate(f):
f.is_plugin = True
f.is_enabled = enabled
f.plugin_name = name
f.plugin_desc = desc
f.plugin_type = plugin_type
f.ratelimit_class = ratelimit_class
plugin_storage[plugin_type].append(f)
return f
return decorate
# def plugin_alias(name):
# """A decorator to add an alias to a plugin function"""
#
# def decorate(f):
# plugin_storage[f.plugin_type].append(f)
# return f
#
# return decorate
def plugin_enabled_get(urlbot_plugin):
plugin_section = config.runtimeconf_deepget('plugins.{}'.format(urlbot_plugin.plugin_name))
if plugin_section and "enabled" in plugin_section:
return plugin_section.as_bool("enabled")
else:
return urlbot_plugin.is_enabled
@config.config_locked
def plugin_enabled_set(plugin, enabled):
if plugin.plugin_name not in config.runtime_config_store['plugins']:
config.runtime_config_store['plugins'][plugin.plugin_name] = {}
config.runtime_config_store['plugins'][plugin.plugin_name]['enabled'] = enabled
config.runtimeconf_persist()