avoid repeatedly instantiating bot

This commit is contained in:
lanvent
2023-03-11 02:20:39 +08:00
parent 8fa4041fc2
commit 38c8ceba12
3 changed files with 44 additions and 33 deletions

9
common/singleton.py Normal file
View File

@@ -0,0 +1,9 @@
def singleton(cls):
instances = {}
def get_instance(*args, **kwargs):
if cls not in instances:
instances[cls] = cls(*args, **kwargs)
return instances[cls]
return get_instance