|
@@ -46,6 +46,7 @@ interface IWorkerOption {
|
|
|
lockfile: string;
|
|
|
webshotCookiesLockfile: string;
|
|
|
bot: QQBot;
|
|
|
+ inactiveHours: string[];
|
|
|
workInterval: number;
|
|
|
webshotDelay: number;
|
|
|
mode: number;
|
|
@@ -203,6 +204,7 @@ export default class {
|
|
|
private client: IgApiClient;
|
|
|
private lock: ILock;
|
|
|
private lockfile: string;
|
|
|
+ private inactiveHours: string[];
|
|
|
private workInterval: number;
|
|
|
private bot: QQBot;
|
|
|
private webshotDelay: number;
|
|
@@ -232,6 +234,7 @@ export default class {
|
|
|
this.session = new SessionManager(this.client, opt.sessionLockfile, opt.credentials, opt.codeServicePort);
|
|
|
this.lockfile = opt.lockfile;
|
|
|
this.lock = opt.lock;
|
|
|
+ this.inactiveHours = opt.inactiveHours;
|
|
|
this.workInterval = opt.workInterval;
|
|
|
this.bot = opt.bot;
|
|
|
this.webshotDelay = opt.webshotDelay;
|
|
@@ -334,6 +337,7 @@ export default class {
|
|
|
} = {};
|
|
|
|
|
|
private workForAll = () => {
|
|
|
+ if (this.isInactiveTime) return;
|
|
|
const idToUserMap: {[id: number]: UserFeedResponseUser} = {};
|
|
|
Promise.all(Object.entries(this.lock.threads).map(entry => {
|
|
|
const id = entry[1].id;
|
|
@@ -367,11 +371,20 @@ export default class {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
+ public get isInactiveTime() {
|
|
|
+ const timeToEpoch = (h = 0, m = 0) => new Date().setHours(h, m, 0, 0);
|
|
|
+ return this.inactiveHours
|
|
|
+ .map(rangeStr => ((start, end) => ({start, end}))(
|
|
|
+ ...rangeStr.split('-', 2).map(timeStr => timeToEpoch(...timeStr.split(':', 2).map(Number))) as [number, number?]
|
|
|
+ ))
|
|
|
+ .some(range => (now => now >= range.start && now < range.end)(Date.now()));
|
|
|
+ }
|
|
|
+
|
|
|
public work = () => {
|
|
|
const lock = this.lock;
|
|
|
logger.debug(`current cache: ${JSON.stringify(this.cache)}`);
|
|
|
if (this.workInterval < 1) this.workInterval = 1;
|
|
|
- if (lock.feed.length === 0) {
|
|
|
+ if (this.isInactiveTime || lock.feed.length === 0) {
|
|
|
setTimeout(this.work, this.workInterval * 1000);
|
|
|
return;
|
|
|
}
|