Skip to content

Commit

Permalink
feat: タコピー構文に教員名を変更できるオプション-cを追加 (#585)
Browse files Browse the repository at this point in the history
* feat: オプションの追加

* オプション追加実装に伴うテストケースの追加

* chore: テストの引数の変更

* refactor: オプション引数への再設計( #586 対応待ち )

* fix: オプションの設定もれの修正

* chore: テストケースの修正

* chore: deletion comment

Co-authored-by: Mikuroさいな <ryosukadnak@gmail.com>

* fix: テストケースの追加 修正

* refactor: オプション・フラグの重複時への対応

* feat: 引数不足時のテストケースの追加

* chore: ヘルプメッセージの親切化

Co-authored-by: m2en <me@m2en.dev>

Co-authored-by: Mikuroさいな <ryosukadnak@gmail.com>
Co-authored-by: m2en <me@m2en.dev>
  • Loading branch information
3 people authored Nov 26, 2022
1 parent 4654a47 commit 9c24742
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
52 changes: 52 additions & 0 deletions src/service/command/meme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,58 @@ describe('meme', () => {
);
});

it('use case of takopi (-c)', async () => {
await responder.on(
createMockMessage(
parseStringsOrThrow(
['takopi', '-c', 'こるく', 'いっそう'],
responder.schema
),
(message) => {
expect(message).toStrictEqual({
description: `こるく「いっそう、出して」\nりにあ「わ、わかんないっピ.......」`
});
},
{
senderName: 'りにあ'
}
)
);
});

it('use case of takopi (-f, -c)', async () => {
await responder.on(
createMockMessage(
parseStringsOrThrow(
['takopi', '-f', '-c', 'こるく', 'いっそう'],
responder.schema
),
(message) => {
expect(message).toStrictEqual({
description: `りにあ「いっそう、出して」\nこるく「わ、わかんないっピ.......」`
});
},
{
senderName: 'りにあ'
}
)
);
});

it('few arguments of takopi (-c)', async () => {
await responder.on(
createMockMessage(
parseStringsOrThrow(['takopi', '-c', 'こるく'], responder.schema),
(message) => {
expect(message).toStrictEqual({
description: '(引数が)わ、わかんないっピ.......',
title: '引数が不足してるみたいだ。'
});
}
)
);
});

it('use case of n', async () => {
await responder.on(
createMockMessage(
Expand Down
25 changes: 19 additions & 6 deletions src/service/command/meme/takopi.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import type { MemeTemplate } from '../../../model/meme-template.js';

const takopiFlags = ['f'] as const;
const takopiOptions = ['c'] as const;

export const takopi: MemeTemplate<typeof takopiFlags[number], never> = {
export const takopi: MemeTemplate<
typeof takopiFlags[number],
typeof takopiOptions[number]
> = {
commandNames: ['takopi'],
description:
'「〜、出して」\n`-f` で教員と自分の名前の位置を反対にします。([idea: フライさん](https://github.com/approvers/OreOreBot2/issues/90))',
'「〜、出して」\n`-f` で教員と自分の名前の位置を反対にします。\n`-c <教員の名前> <出すもの>`で教員の名前も変更可能です。\n([idea: フライさん](https://github.com/approvers/OreOreBot2/issues/90))',
flagsKeys: takopiFlags,
optionsKeys: [],
optionsKeys: takopiOptions,
errorMessage: '(引数が)わ、わかんないっピ.......',
generate(args, author) {
if (args.flags.f)
return `${author}${args.body}、出して」\n教員「わ、わかんないっピ.......」`;
return `教員「${args.body}、出して」\n${author}「わ、わかんないっピ.......」`;
const takopiArgs = {
takopi: author,
shizuka: args.options.c ?? '教員',
goods: args.body ?? '課題'
};

if (args.flags.f) {
const temp: string = takopiArgs.takopi;
takopiArgs.takopi = takopiArgs.shizuka;
takopiArgs.shizuka = temp;
}
return `${takopiArgs.shizuka}${takopiArgs.goods}、出して」\n${takopiArgs.takopi}「わ、わかんないっピ.......」`;
}
};

0 comments on commit 9c24742

Please sign in to comment.