Ver Fonte

Merge branch 'koishi-production' into fleets-koishi

Mike L há 3 anos atrás
pai
commit
ccd0eb8c6c
6 ficheiros alterados com 14 adições e 16 exclusões
  1. 1 2
      dist/koishi.js
  2. 4 4
      dist/main.js
  3. 1 1
      dist/utils.js
  4. 1 2
      src/koishi.ts
  5. 4 4
      src/main.ts
  6. 3 3
      src/utils.ts

+ 1 - 2
dist/koishi.js

@@ -14,7 +14,6 @@ const koishi_1 = require("koishi");
 require("koishi-adapter-onebot");
 const command_1 = require("./command");
 const loggers_1 = require("./loggers");
-const utils_1 = require("./utils");
 const logger = loggers_1.getLogger('qqbot');
 const cqUrlFix = (factory) => (...args) => factory(...args).replace(/(?<=\[CQ:.*)url=(?=(base64|file|https?):\/\/)/, 'file=');
 exports.Message = {
@@ -87,7 +86,7 @@ class default_1 {
         this.sendToUser = (userID, message) => new Promise(resolve => {
             this.enqueue('private', userID, () => this.bot.sendPrivateMessage(userID, message).then(resolve));
         });
-        this.sendTo = (subscriber, messageChain) => utils_1.chainPromises((splitted => [splitted.message, ...splitted.attachments])(exports.Message.separateAttachment(messageChain)).map(msg => {
+        this.sendTo = (subscriber, messageChain) => Promise.all((splitted => [splitted.message, ...splitted.attachments])(exports.Message.separateAttachment(messageChain)).map(msg => {
             switch (subscriber.chatType) {
                 case 'group':
                     return this.sendToGroup(subscriber.chatID.toString(), msg);

+ 4 - 4
dist/main.js

@@ -12,14 +12,14 @@ const twitter_1 = require("./twitter");
 const logger = loggers_1.getLogger();
 const sections = [
     {
-        header: 'MiraiTS Twitter Bot',
+        header: 'GoCQHTTP Twitter Bot',
         content: 'The QQ Bot that forwards twitters.',
     },
     {
         header: 'Synopsis',
         content: [
-            '$ mirai-twitter-bot {underline config.json}',
-            '$ mirai-twitter-bot {bold --help}',
+            '$ twitter-bot {underline config.json}',
+            '$ twitter-bot {bold --help}',
         ],
     },
     {
@@ -62,7 +62,7 @@ if (requiredFields.some((value) => config[value] === undefined)) {
 }
 optionalFields.forEach(key => {
     if (config[key] === undefined || typeof (config[key]) !== typeof (exampleConfig[key])) {
-        if (key in warningFields)
+        if (warningFields.includes(key))
             logger.warn(`${key} is undefined, use ${exampleConfig[key] || 'empty string'} as default`);
         config[key] = exampleConfig[key];
     }

+ 1 - 1
dist/utils.js

@@ -1,7 +1,7 @@
 "use strict";
 Object.defineProperty(exports, "__esModule", { value: true });
 exports.BigNumOps = exports.chainPromises = void 0;
-const chainPromises = (promises, reducer = (p1, p2) => p1.then(() => p2), initialValue) => promises.reduce(reducer, Promise.resolve(initialValue));
+const chainPromises = (lazyPromises, reducer = (lp1, lp2) => (p) => lp1(p).then(lp2), initialValue) => lazyPromises.reduce(reducer, p => Promise.resolve(p))(initialValue);
 exports.chainPromises = chainPromises;
 const splitBigNumAt = (num, at) => num.replace(RegExp(String.raw `^([+-]?)(\d+)(\d{${at}})$`), '$1$2,$1$3')
     .replace(/^([^,]*)$/, '0,$1').split(',')

+ 1 - 2
src/koishi.ts

@@ -3,7 +3,6 @@ import 'koishi-adapter-onebot';
 
 import { parseCmd, view } from './command';
 import { getLogger } from './loggers';
-import { chainPromises } from './utils';
 
 const logger = getLogger('qqbot');
 
@@ -98,7 +97,7 @@ export default class {
     this.enqueue('private', userID, () => this.bot.sendPrivateMessage(userID, message).then(resolve));
   });
 
-  public sendTo = (subscriber: IChat, messageChain: string) => chainPromises(
+  public sendTo = (subscriber: IChat, messageChain: string) => Promise.all(
     (splitted => [splitted.message, ...splitted.attachments])(
       Message.separateAttachment(messageChain)
     ).map(msg => {

+ 4 - 4
src/main.ts

@@ -15,14 +15,14 @@ const logger = getLogger();
 
 const sections: commandLineUsage.Section[] = [
   {
-    header: 'MiraiTS Twitter Bot',
+    header: 'GoCQHTTP Twitter Bot',
     content: 'The QQ Bot that forwards twitters.',
   },
   {
     header: 'Synopsis',
     content: [
-      '$ mirai-twitter-bot {underline config.json}',
-      '$ mirai-twitter-bot {bold --help}',
+      '$ twitter-bot {underline config.json}',
+      '$ twitter-bot {bold --help}',
     ],
   },
   {
@@ -75,7 +75,7 @@ if (requiredFields.some((value) => config[value] === undefined)) {
 
 optionalFields.forEach(key => {
   if (config[key] === undefined || typeof(config[key]) !== typeof (exampleConfig[key])) {
-    if (key in warningFields) logger.warn(`${key} is undefined, use ${exampleConfig[key] || 'empty string'} as default`);
+    if (warningFields.includes(key)) logger.warn(`${key} is undefined, use ${exampleConfig[key] || 'empty string'} as default`);
     config[key] = exampleConfig[key as keyof Config];
   }
 });

+ 3 - 3
src/utils.ts

@@ -1,8 +1,8 @@
 export const chainPromises = <T>(
-  promises: Promise<T>[],
-  reducer = (p1: Promise<T>, p2: Promise<T>) => p1.then(() => p2),
+  lazyPromises: ((p: T) => Promise<T>)[],
+  reducer = (lp1: (p: T) => Promise<T>, lp2: (p: T) => Promise<T>) => (p: T) => lp1(p).then(lp2),
   initialValue?: T
-) => promises.reduce(reducer, Promise.resolve(initialValue));
+) => lazyPromises.reduce(reducer, p => Promise.resolve(p))(initialValue);
 
 const splitBigNumAt = (num: string, at: number) => num.replace(RegExp(String.raw`^([+-]?)(\d+)(\d{${at}})$`), '$1$2,$1$3')
   .replace(/^([^,]*)$/, '0,$1').split(',')