jerrita пре 9 месеци
родитељ
комит
2163272620
1 измењених фајлова са 22 додато и 2 уклоњено
  1. 22 2
      plugins/anon/glm.py

+ 22 - 2
plugins/anon/glm.py

@@ -6,6 +6,7 @@ from anon import PluginManager, Plugin
 from anon.event import MessageEvent
 from anon.event.message import GroupMessage
 from anon.logger import logger
+from anon.storage import Storage
 
 
 class GlmClient:
@@ -78,13 +79,25 @@ class GlmClient:
 
 class GlmPlugin(Plugin):
     _client: GlmClient
+    _group_shared_cache: bool
 
     async def on_load(self):
         self._client = GlmClient()
+        self.storage = Storage('glm')
+        if self.storage['system'] is not None:
+            logger.info('GlmPlugin: load cache')
+            self._client.system = self.storage['system']
+            self._group_shared_cache = self.storage['group_shared_cache']
+            logger.info(f'GlmPlugin: system prompt: {self._client.system}')
+        else:
+            self.storage['group_shared_cache'] = False
+            self._group_shared_cache = False
+            self.storage['system'] = self._client.system
+            logger.info('GlmPlugin: init cache')
 
     async def on_event(self, event: MessageEvent):
         rid = event.sender.user_id
-        if isinstance(event, GroupMessage):
+        if isinstance(event, GroupMessage) and self._group_shared_cache:
             rid = event.gid
 
         if event.raw.startswith('glm'):
@@ -106,7 +119,8 @@ class GlmPlugin(Plugin):
                     '   - curlen [int]: set max cut length\n'
                     '   - s/sys [str]: set system prompt\n'
                     '   - g/sys: get system prompt\n'
-                    '   - clear: clear cache'
+                    '   - clear: clear cache\n'
+                    '   - sw: switch group shared cache'
                 )
             if cmd == 'cutlen':
                 self._client.max_cut_length = int(args[0])
@@ -114,12 +128,18 @@ class GlmPlugin(Plugin):
             if cmd == 's/sys':
                 self._client.system = ' '.join(args)
                 self._client.cache.clear()
+                self.storage['system'] = self._client.system
                 await event.reply(f'system prompt set to: {" ".join(args)}')
             if cmd == 'g/sys':
                 await event.reply(f'system prompt: {self._client.system}')
             if cmd == 'clear':
                 self._client.cache.clear()
                 await event.reply('cache cleared')
+            if cmd == 'sw':
+                self._group_shared_cache = not self._group_shared_cache
+                self.storage['group_shared_cache'] = self._group_shared_cache
+                await event.reply(
+                    f'group_shared_cache set to {self._group_shared_cache}')
 
 
 PluginManager().register_plugin(GlmPlugin([MessageEvent]))