-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/version' into square
- Loading branch information
Showing
4 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
client: meta.clientVersion | ||
}; | ||
}); | ||
}; | ||
|
||
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); | ||
}); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |