Skip to content

Commit

Permalink
Merge pull request #9 from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
u1-liquid authored Jan 5, 2025
2 parents 8b3a5e6 + 4f49842 commit 5f28177
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type { User } from '@/misskey/user.js';
import Stream from '@/stream.js';
import log from '@/utils/log.js';
import { sleep } from './utils/sleep.js';
import pkg from '../package.json' assert { type: 'json' };
import pkg from '../package.json' with { type: 'json' };

type MentionHook = (msg: Message) => Promise<boolean | HandlerResult>;
type ContextHook = (key: any, msg: Message, data?: any) => Promise<void | boolean | HandlerResult>;
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Config = {
memoryDir?: string;
};

import config from '../config.json' assert { type: 'json' };
import config from '../config.json' with { type: 'json' };

config.wsUrl ??= config.host.replace('http', 'ws');
config.apiUrl ??= config.host + '/api';
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import promiseRetry from 'promise-retry';
import from './ai.js';
import config from './config.js';
import _log from './utils/log.js';
import pkg from '../package.json' assert { type: 'json' };
import pkg from '../package.json' with { type: 'json' };

import CoreModule from './modules/core/index.js';
import TalkModule from './modules/talk/index.js';
Expand Down
29 changes: 25 additions & 4 deletions src/modules/check-custom-emojis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,35 @@ export default class extends Module {
}

@bindThis
private async post() {
private async post(byMentionHook:boolean = false) {
this.log('Start to Check CustomEmojis.');
const lastEmoji = this.lastEmoji.find({});

const lastId = lastEmoji.length != 0 ? lastEmoji[0].id : null;
const emojisData = await this.checkCumstomEmojis(lastId);
if (emojisData.length == 0) {
let emojisData:any[] | null = null;
try {
emojisData = await this.checkCumstomEmojis(lastId);
} catch (err: unknown) {
this.log('Error By API(admin/emoji/list)');
if (err instanceof Error) {
this.log(`${err.name}\n${err.message}`);
}
}
if (emojisData === null) {
const errMessage = 'read:admin:emoji権限がないため、エラーが発生しました。\nカスタム絵文字管理の権限が付与されているか見直しをお願いします。';
this.log(errMessage);
await this.ai.post({
text: errMessage
});
return;
}
else if (emojisData.length == 0) {
this.log('No CustomEmojis Added.');
if (byMentionHook) {
await this.ai.post({
text: serifs.checkCustomEmojis.nothing
});
}
return;
}

Expand Down Expand Up @@ -148,7 +169,7 @@ export default class extends Module {
this.log('Check CustomEmojis requested');
}

await this.post();
await this.post(true);

return {
reaction: 'like'
Expand Down
3 changes: 2 additions & 1 deletion src/serifs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,8 @@ export default {
post: (server_name, num) => `${server_name}${num}件の絵文字が追加されました!`,
emojiPost: emoji => `:${emoji}:\n(\`${emoji}\`) #AddCustomEmojis`,
postOnce: (server_name, num, text) => `${server_name}${num}件の絵文字が追加されました!\n${text} #AddCustomEmojis`,
emojiOnce: emoji => `:${emoji}:(\`${emoji}\`)`
emojiOnce: emoji => `:${emoji}:(\`${emoji}\`)`,
nothing: '絵文字を確認しましたが、なにも追加されていないみたいです',
},

sleepReport: {
Expand Down

0 comments on commit 5f28177

Please sign in to comment.