Skip to content

Commit 786c8a9

Browse files
author
Liki4
committed
update: add meme help action
1 parent 5efb991 commit 786c8a9

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
mod bot;
22
mod meme;
33

4-
use std::env;
54
use {
65
crate::bot::{
76
bot_init,
@@ -15,6 +14,7 @@ use {
1514
command,
1615
command::Command,
1716
},
17+
std::env,
1818
teloxide::{
1919
prelude::*,
2020
utils::command::BotCommands,
@@ -43,8 +43,9 @@ async fn main() {
4343
dptree::filter(|msg: Message| msg.media_group_id().is_some())
4444
.branch(
4545
dptree::filter(|msg: Message| {
46-
msg.caption()
47-
.map_or(false, |caption| Command::parse(caption, &env::var("BOT_NAME").unwrap()).is_ok())
46+
msg.caption().map_or(false, |caption| {
47+
Command::parse(caption, &env::var("BOT_NAME").unwrap()).is_ok()
48+
})
4849
})
4950
.endpoint(media_group_with_command_handler),
5051
)

src/meme/cmd.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,34 @@ use {
2626
},
2727
};
2828

29+
const HELP_MSG: &str = r#"
30+
`/meme help` \- display this message
31+
`/meme list` \- list all memes
32+
`/meme info <key/keyword>` \- display meme information
33+
`/meme search <keyword>` \- search meme key by keyword
34+
`/meme random [args]` \- generate a random meme
35+
`/meme generate <key/keyword> [args]` \- generate a specific meme
36+
37+
args \= `[<text1> <text2>] [<@someone> <@someone_else>]`
38+
39+
**random** & **generate** action can pass photo using `@someone`, append as photo and reply to a media group message
40+
41+
command sender's **first\_name** & **profile\_photo** will append to end of texts\_list and photos\_list
42+
43+
see https://github\.com/Liki4/Liki4TeloxideBot for more details\.
44+
"#;
45+
2946
pub async fn meme_command_handler(
3047
bot: &Bot, msg: &Message, action: MemeAction, args: Vec<String>,
3148
) -> ResponseResult<Message> {
3249
let error = match action {
50+
MemeAction::Help => {
51+
return bot
52+
.send_message(msg.chat.id, HELP_MSG)
53+
.parse_mode(ParseMode::MarkdownV2)
54+
.reply_parameters(ReplyParameters::new(msg.id))
55+
.await;
56+
}
3357
MemeAction::Info => match args.first() {
3458
Some(keyword) => {
3559
if let Some(key) = MEME_KEYWORD_KEY_MAPPING.get().unwrap().get(keyword) {

src/meme/mod.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,19 @@ mod utils;
44

55
use {
66
std::{
7-
error::Error,
87
fmt::{
98
self,
109
Display,
1110
Formatter,
1211
},
1312
str::FromStr,
1413
},
15-
teloxide::utils::command::{
16-
ParseError,
17-
ParseError::IncorrectFormat,
18-
},
14+
teloxide::utils::command::ParseError,
1915
};
2016

2117
#[derive(Debug, PartialEq, Clone)]
2218
pub enum MemeAction {
19+
Help,
2320
List,
2421
Search,
2522
Info,
@@ -37,16 +34,15 @@ impl FromStr for MemeAction {
3734
"search" => Ok(MemeAction::Search),
3835
"random" => Ok(MemeAction::Random),
3936
"generate" => Ok(MemeAction::Generate),
40-
_ => Err(IncorrectFormat(
41-
Box::<dyn Error + Send + Sync + 'static>::from("Unknown MemeAction"),
42-
)),
37+
_ => Ok(MemeAction::Help),
4338
}
4439
}
4540
}
4641

4742
impl Display for MemeAction {
4843
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
4944
match self {
45+
MemeAction::Help => write!(f, "help"),
5046
MemeAction::Info => write!(f, "info"),
5147
MemeAction::List => write!(f, "list"),
5248
MemeAction::Search => write!(f, "search"),

0 commit comments

Comments
 (0)