2023-03-08 15:21:37 +08:00
|
|
|
|
import threading
|
|
|
|
|
|
2023-01-01 23:18:32 +08:00
|
|
|
|
context = {
|
|
|
|
|
'inst': {
|
|
|
|
|
'database.manager.DatabaseManager': None,
|
|
|
|
|
'openai.manager.OpenAIInteract': None,
|
|
|
|
|
'qqbot.manager.QQBotManager': None,
|
2023-01-02 00:35:36 +08:00
|
|
|
|
},
|
2023-03-08 15:21:37 +08:00
|
|
|
|
'pool_ctl': None,
|
2023-01-02 00:35:36 +08:00
|
|
|
|
'logger_handler': None,
|
2023-01-04 17:09:57 +08:00
|
|
|
|
'config': None,
|
2023-01-13 16:49:56 +08:00
|
|
|
|
'plugin_host': None,
|
2023-01-01 23:18:32 +08:00
|
|
|
|
}
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock = threading.Lock()
|
2023-01-01 23:18:32 +08:00
|
|
|
|
|
2023-03-08 15:21:37 +08:00
|
|
|
|
### context耦合度非常高,需要大改 ###
|
2023-01-04 17:09:57 +08:00
|
|
|
|
def set_config(inst):
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
2023-01-04 17:09:57 +08:00
|
|
|
|
context['config'] = inst
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.release()
|
2023-01-04 17:09:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_config():
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
|
|
|
|
t = context['config']
|
|
|
|
|
context_lock.release()
|
|
|
|
|
return t
|
2023-01-04 17:09:57 +08:00
|
|
|
|
|
|
|
|
|
|
2023-01-01 23:18:32 +08:00
|
|
|
|
def set_database_manager(inst):
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
2023-01-01 23:18:32 +08:00
|
|
|
|
context['inst']['database.manager.DatabaseManager'] = inst
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.release()
|
2023-01-01 23:18:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_database_manager():
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
|
|
|
|
t = context['inst']['database.manager.DatabaseManager']
|
|
|
|
|
context_lock.release()
|
|
|
|
|
return t
|
2023-01-01 23:18:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_openai_manager(inst):
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
2023-01-01 23:18:32 +08:00
|
|
|
|
context['inst']['openai.manager.OpenAIInteract'] = inst
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.release()
|
2023-01-01 23:18:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_openai_manager():
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
|
|
|
|
t = context['inst']['openai.manager.OpenAIInteract']
|
|
|
|
|
context_lock.release()
|
|
|
|
|
return t
|
2023-01-01 23:18:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_qqbot_manager(inst):
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
2023-01-01 23:18:32 +08:00
|
|
|
|
context['inst']['qqbot.manager.QQBotManager'] = inst
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.release()
|
2023-01-01 23:18:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_qqbot_manager():
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
|
|
|
|
t = context['inst']['qqbot.manager.QQBotManager']
|
|
|
|
|
context_lock.release()
|
|
|
|
|
return t
|
2023-01-13 16:49:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def set_plugin_host(inst):
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
2023-01-13 16:49:56 +08:00
|
|
|
|
context['plugin_host'] = inst
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.release()
|
2023-01-13 16:49:56 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_plugin_host():
|
2023-03-08 15:21:37 +08:00
|
|
|
|
context_lock.acquire()
|
|
|
|
|
t = context['plugin_host']
|
|
|
|
|
context_lock.release()
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
def set_thread_ctl(inst):
|
|
|
|
|
context_lock.acquire()
|
|
|
|
|
context['pool_ctl'] = inst
|
|
|
|
|
context_lock.release()
|
|
|
|
|
|
|
|
|
|
from pkg.utils import ThreadCtl
|
|
|
|
|
def get_thread_ctl() -> ThreadCtl:
|
|
|
|
|
context_lock.acquire()
|
|
|
|
|
t = context['pool_ctl']
|
|
|
|
|
context_lock.release()
|
|
|
|
|
return t
|