Kaynağa Gözat

fix deduplication of guild subscribers

Mike L 2 yıl önce
ebeveyn
işleme
aec953b6cf
5 değiştirilmiş dosya ile 7 ekleme ve 19 silme
  1. 2 2
      dist/command.js
  2. 1 7
      dist/koishi.js
  3. 2 2
      src/command.ts
  4. 1 7
      src/koishi.ts
  5. 1 1
      src/model.d.ts

+ 2 - 2
dist/command.js

@@ -34,7 +34,7 @@ function linkFinder(checkedMatch, chat, lock) {
     const link = Object.keys(lock.threads).find(realLink => normalizedLink === realLink.replace(/\/@/, '/').toLowerCase());
     if (!link)
         return [null, -1];
-    const index = lock.threads[link].subscribers.findIndex(({ chatID, chatType }) => chat.chatID === chatID && chat.chatType === chatType);
+    const index = lock.threads[link].subscribers.findIndex(({ chatID, chatType }) => chat.chatID.toString() === chatID.toString() && chat.chatType === chatType);
     return [link, index];
 }
 function sub(chat, args, reply, lock, lockfile) {
@@ -101,7 +101,7 @@ function unsubAll(chat, args, reply, lock, lockfile) {
         return reply('请先添加机器人为好友。');
     }
     Object.entries(lock.threads).forEach(([link, { subscribers }]) => {
-        const index = subscribers.findIndex(({ chatID, chatType }) => chat.chatID === chatID && chat.chatType === chatType);
+        const index = subscribers.findIndex(({ chatID, chatType }) => chat.chatID.toString() === chatID.toString() && chat.chatType === chatType);
         if (index === -1)
             return;
         subscribers.splice(index, 1);

+ 1 - 7
dist/koishi.js

@@ -75,14 +75,8 @@ class default_1 {
             if (session.type !== 'message')
                 return null;
             if (session.subsubtype === 'guild') {
-                const channel = session.onebot.channel_id;
-                const guild = session.onebot.guild_id;
                 return {
-                    chatID: {
-                        channel,
-                        guild,
-                        toString: () => `${guild}:${channel}`,
-                    },
+                    chatID: `${session.onebot.guild_id}:${session.onebot.channel_id}`,
                     chatType: 'guild',
                 };
             }

+ 2 - 2
src/command.ts

@@ -42,7 +42,7 @@ function linkFinder(checkedMatch: string[], chat: IChat, lock: ILock): [string,
   );
   if (!link) return [null, -1];
   const index = lock.threads[link].subscribers.findIndex(({chatID, chatType}) =>
-    chat.chatID === chatID && chat.chatType === chatType
+    chat.chatID.toString() === chatID.toString() && chat.chatType === chatType
   );
   return [link, index];
 }
@@ -113,7 +113,7 @@ function unsubAll(chat: IChat, args: string[], reply: (msg: string) => any,
   }
   Object.entries(lock.threads).forEach(([link, {subscribers}]) => {
     const index = subscribers.findIndex(({chatID, chatType}) =>
-      chat.chatID === chatID && chat.chatType === chatType
+      chat.chatID.toString() === chatID.toString() && chat.chatType === chatType
     );
     if (index === -1) return;
     subscribers.splice(index, 1);

+ 1 - 7
src/koishi.ts

@@ -93,14 +93,8 @@ export default class {
   private getChat = async (session: Session): Promise<IChat> => {
     if (session.type !== 'message') return null;
     if (session.subsubtype === 'guild') {
-      const channel = session.onebot.channel_id;
-      const guild = session.onebot.guild_id;
       return {
-        chatID: {
-          channel,
-          guild,
-          toString: () => `${guild}:${channel}`,
-        },
+        chatID: `${session.onebot.guild_id}:${session.onebot.channel_id}`,
         chatType: 'guild',
       };
     }

+ 1 - 1
src/model.d.ts

@@ -20,7 +20,7 @@ interface ITempChat extends IChatBase {
 }
 
 interface IGuildChat extends IChatBase {
-  chatID: {channel: string, guild: string, toString: () => string};
+  chatID: string;
   chatType: 'guild';
 }