Skip to content

Commit 05a1cd6

Browse files
committed
feat: add bad answers
1 parent 2185c7e commit 05a1cd6

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

src/assets/bad_answer_book.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pub static ANSWERS: &[&str] = &[
2+
"绷",
3+
"急",
4+
"典",
5+
"孝",
6+
"赢",
7+
"乐",
8+
"你已急哭",
9+
"你看你又急",
10+
"666",
11+
"你又懂了",
12+
"急了",
13+
"感觉质量不如原神",
14+
"玩原神玩的",
15+
"?",
16+
"点开主页,看到原神,满意离开",
17+
"寄",
18+
"我知道你很急,但你先别急",
19+
"何意味",
20+
];

src/assets/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pub mod answer_book;
2+
pub mod bad_answer_book;
23
pub mod idiom;
34
pub mod tarot;

src/mods/answer_book.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use teloxide_core::prelude::*;
66
use teloxide_core::types::*;
77

88
use crate::assets::answer_book;
9+
use crate::assets::bad_answer_book;
910
use crate::linquebot::*;
1011
use crate::Consumption;
1112

@@ -23,6 +24,20 @@ fn on_message(ctx: &mut Context, _message: &Message) -> Consumption {
2324
.into()
2425
}
2526

27+
fn on_bad_answer_message(ctx: &mut Context, _message: &Message) -> Consumption {
28+
let ctx = ctx.task();
29+
async move {
30+
let chosen = bad_answer_book::ANSWERS
31+
.choose(&mut rand::thread_rng())
32+
.expect("not empty");
33+
let res = ctx.reply(*chosen).send().await;
34+
if let Err(err) = res {
35+
warn!("Failed to send reply: {}", err);
36+
}
37+
}
38+
.into()
39+
}
40+
2641
pub static MODULE: Module = Module {
2742
kind: ModuleKind::Command(ModuleDescription {
2843
name: "answer",
@@ -34,3 +49,15 @@ pub static MODULE: Module = Module {
3449
}),
3550
task: on_message,
3651
};
52+
53+
pub static MODULE_BAD: Module = Module {
54+
kind: ModuleKind::Command(ModuleDescription {
55+
name: "bad_answer",
56+
description: "抽象之书",
57+
description_detailed: Some(concat!(
58+
"该命令不需要参数。\n",
59+
"怪东西。"
60+
)),
61+
}),
62+
task: on_bad_answer_message,
63+
};

src/mods/help.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,10 @@ fn gen_help_message(app: &App) -> (String, InlineKeyboardMarkup) {
5151

5252
let mut keyboards: Vec<Vec<InlineKeyboardButton>> = Vec::new();
5353

54-
loop {
55-
if let Some(x) = keyboards_iter.next() {
56-
keyboards.push(x.into_iter().collect::<Vec<_>>());
57-
} else {
58-
if let Some(x) = keyboards_iter.into_remainder() {
59-
keyboards.push(x.collect::<Vec<_>>());
60-
}
61-
break;
62-
}
54+
for x in keyboards_iter.by_ref() {
55+
keyboards.push(x.into_iter().collect());
6356
}
57+
keyboards.push(keyboards_iter.into_remainder().collect());
6458

6559
let message = format!(
6660
"{HELP_HEAD}

src/mods/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ pub static MODULES: &[&Module] = &[
4242
&todo::MODULE,
4343
&hitokoto::MODULE,
4444
&answer_book::MODULE,
45+
&answer_book::MODULE_BAD,
4546
&say::MODULE,
4647
&repeater::TOGGLE,
4748
&markov::TOGGLE,

0 commit comments

Comments
 (0)