Skip to content

Commit

Permalink
Merge branch 'feat/version' into square
Browse files Browse the repository at this point in the history
  • Loading branch information
n1lsqn committed Feb 8, 2024
2 parents 1347032 + 8d50e18 commit 4f27d41
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@types/twemoji-parser": "13.1.4",
"@types/uuid": "9.0.7",
"@types/ws": "8.5.10",
"accurate-interval": "1.0.9",
"canvas": "2.11.2",
"chalk": "5.3.0",
"formdata-node": "6.0.3",
Expand Down
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import PollModule from './modules/poll/index.js';
import ReminderModule from './modules/reminder/index.js';
import CheckCustomEmojisModule from './modules/check-custom-emojis/index.js';
import RecommendMusicModule from './modules/recommend-music/index.js';
import CheckVersion from './modules/checkVersion/index.js';
import JihouModule from './modules/jihou/index.js';

console.log(' __ ____ _____ ___ ');
console.log(' /__\\ (_ _)( _ )/ __)');
Expand Down Expand Up @@ -99,6 +101,8 @@ promiseRetry(retry => {
new ReminderModule(),
new RecommendMusicModule(),
new CheckCustomEmojisModule(),
new CheckVersion(),
new JihouModule()
]);
}).catch(e => {
log(chalk.red('Failed to fetch the account'));
Expand Down
83 changes: 83 additions & 0 deletions src/modules/checkVersion/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import Module from '@/module.js';
import Message from '@/message.js';
import { bindThis } from '@/decorators.js';

type Version = {
server: string;
client: string;
};

export default class extends Module {
public readonly name = 'checkVersion';

private latest?: Version;

@bindThis
public install() {
this.versionCheck();
setInterval(this.versionCheck, 1000 * 60 * 60 * 1);

return {
mentionHook: this.mentionHook
};
}

public versionCheck = () => {
this.getVersion()
.then(fetched => {
this.log(`Version fetched: ${JSON.stringify(fetched)}`);

if (this.latest != null && fetched != null) {
const serverChanged = this.latest.server !== fetched.server;

if (serverChanged) {
const v = `${serverChanged ? '**' : ''}${this.latest.server}${this.mfmVersion(fetched.server)}\n${serverChanged ? '**' : ''}`;

this.log(`Version changed: ${v}`);

this.ai.post({ text: `${v}にアップデートされたようですよ!` });
}
}

this.latest = fetched;
})
.catch(e => this.log(`warn: ${e}`));
};

@bindThis
private async mentionHook(msg: Message) {
if (msg.text == null) {
return false;
} else if (msg.includes(['サーバーバージョン', 'バージョン確認', 'バージョンチェック'])) {
this.getVersion()
.then(meta => {
msg.reply(`${this.mfmVersion(meta.server)} みたいです!`);
})
.catch(() => {
msg.reply(`ごめんなさい、取得に失敗したようです・・・。`);
});
return true;
}
return false;
}

private getVersion = (): Promise<Version> => {
return this.ai.api('meta').then(meta => {
return {
server: meta.version,

Check failure on line 67 in src/modules/checkVersion/index.ts

View workflow job for this annotation

GitHub Actions / build

'meta' is of type 'unknown'.
client: meta.clientVersion

Check failure on line 68 in src/modules/checkVersion/index.ts

View workflow job for this annotation

GitHub Actions / build

'meta' is of type 'unknown'.
};
});
};

private mfmVersion = (v): string => {
if (v == null) return v;
return v.match(/^\d+\.\d+\.\d+$/) ? `[${v}](https://github.com/syuilo/misskey/releases/tag/${v})` : v;
};

private wait = (ms: number): Promise<void> => {
return new Promise(resolve => {
setTimeout(() => resolve(), ms);
});
};
}
45 changes: 45 additions & 0 deletions src/modules/jihou/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Module from '@/module.js';
import accurateInterval from 'accurate-interval';
import { bindThis } from '@/decorators.js';

export default class extends Module {
public readonly name = 'jihou';

@bindThis
public install() {
accurateInterval(this.post, 1000 * 60 * 60, { aligned: true, immediate: true });

return {};
}

@bindThis
private async post() {
const date = new Date();
date.setMinutes(date.getMinutes() + 1);

const hour = date.getHours();

switch (hour) {
default:
break;

case 7:
this.ai.post({
text: `おはようございます!${hour}時です。学校の方もお仕事の方も、お休みの方も無理せず頑張ってください・・・!`
});
break;

case 10:
this.ai.post({
text: `${hour}時ですよー!よい子はそろそろ寝る時間です!`
});
break;

case 3:
this.ai.post({
text: `${hour}時です、夜更かしさんですか?藍は寝る必要がないので傍にいますよ。`
});
break;
}
}
}

0 comments on commit 4f27d41

Please sign in to comment.