Skip to content
This repository has been archived by the owner on Jun 17, 2023. It is now read-only.

Commit

Permalink
set bot commands automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
EAimTY committed Oct 29, 2021
1 parent d75b64e commit 7619a7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "bing-dict-telegram-bot"
description = "A Telegram bot uses Bing Dictionary to translate words and phrases from Chinese to English or English to Chinese"
version = "0.2.2"
version = "0.3.0"
authors = ["EAimTY <ea.imty@gmail.com>"]
edition = "2021"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Options:
In chat:

```
/dict [word / phrase] - Translate a word / phrase
/dict [word / phrase] - Translate a word or phrase
/toggle_command - Toggle translate-all-messages mode for the current chat (default: off)
/toggle_mention - Toggle if I should only react to non-command messages that mentions me in the group. You still need to @ me when using command (default: on)
/about - About this bot
Expand Down
20 changes: 15 additions & 5 deletions src/bot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use futures_util::future::BoxFuture;
use std::{collections::HashSet, sync::Arc};
use tgbot::{
longpoll::LongPoll,
methods::{GetMe, SendMessage},
types::{Command, Me, MessageKind, Update, UpdateKind},
methods::{GetMe, SendMessage, SetMyCommands},
types::{BotCommand, Command, Me, MessageKind, Update, UpdateKind},
webhook::{self, HyperError},
Api, ApiError, Config as ApiConfig, ExecuteError, ParseProxyError, UpdateHandler,
};
Expand All @@ -22,6 +22,16 @@ pub async fn run(config: &Config) -> Result<(), Error> {

let bot_info = api.execute(GetMe).await?;

let commands = vec![
BotCommand::new("dict", "[word / phrase] - Translate a word or phrase"),
BotCommand::new("toggle_command", "Toggle translate-all-messages mode for the current chat (default: off)"),
BotCommand::new("toggle_mention", "Toggle if I should only react to non-command messages that mentions. This only works in groups. You still need to @ me when using command (default: on)"),
BotCommand::new("about", "About this bot"),
BotCommand::new("help", "Get this help message"),
].into_iter().flatten();

api.execute(SetMyCommands::new(commands)).await?;

if config.webhook == 0 {
println!("Running in longpoll mode");
LongPoll::new(api.clone(), Handler::new(api, bot_info))
Expand Down Expand Up @@ -230,7 +240,7 @@ impl UpdateHandler for Handler {
r#"
This is a Telegram bot uses Bing Dictionary to translate words from Chinese to English or English to Chinese.
/dict [word / phrase] - Translate a word / phrase
/dict [word / phrase] - Translate a word or phrase
/toggle_command - Toggle translate-all-messages mode for the current chat (default: off)
/toggle_mention - Toggle if I should only react to non-command messages that mentions me in the group. You still need to @ me when using command (default: on)
Expand All @@ -242,7 +252,7 @@ Use "/help" to get more information.
"/about" => {
result = Some(String::from(
r#"
A Telegram bot uses Bing Dictionary to translate words from Chinese to English or English to Chinese.
A Telegram bot uses Bing Dictionary to translate words and phrases from Chinese to English or English to Chinese.
https://github.com/EAimTY/bing-dict-telegram-bot
"#,
Expand All @@ -252,7 +262,7 @@ https://github.com/EAimTY/bing-dict-telegram-bot
"/help" => {
result = Some(String::from(
r#"
/dict [word / phrase] - Translate a word / phrase
/dict [word / phrase] - Translate a word or phrase
/toggle_command - Toggle translate-all-messages mode for the current chat (default: off)
/toggle_mention - Toggle if I should only react to non-command messages that mentions me in the group. You still need to @ me when using command (default: on)
/about - About this bot
Expand Down

0 comments on commit 7619a7c

Please sign in to comment.