initial commit
This commit is contained in:
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
/target
|
||||
**/*.rs.bk
|
||||
.env
|
||||
1725
Cargo.lock
generated
Normal file
1725
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
14
Cargo.toml
Normal file
14
Cargo.toml
Normal file
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "sarcastifybot"
|
||||
version = "0.1.0"
|
||||
authors = ["Jur van den Berg <Jurl.berg@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
telegram-bot = { git = "https://github.com/telegram-rs/telegram-bot" }
|
||||
|
||||
dotenv = "0.15.0"
|
||||
tokio = "^0.2.0-alpha.6"
|
||||
futures-preview = { version = "=0.3.0-alpha.19", features = ["async-await"] }
|
||||
61
src/main.rs
Normal file
61
src/main.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
use std::env;
|
||||
|
||||
use dotenv::dotenv;
|
||||
use futures::StreamExt;
|
||||
use telegram_bot::*;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
dotenv().ok();
|
||||
|
||||
let token = env::var("TELEGRAM_BOT_TOKEN").expect("TELEGRAM_BOT_TOKEN not set");
|
||||
let api = Api::new(token);
|
||||
|
||||
// Fetch new updates via long poll method
|
||||
let mut stream: UpdatesStream = api.stream();
|
||||
while let Some(update) = stream.next().await {
|
||||
let update: Update = match update {
|
||||
Ok(update) => update,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
if let UpdateKind::InlineQuery(query) = update.kind {
|
||||
let mut option1 = String::new();
|
||||
let mut option2 = String::new();
|
||||
if query.query == "" {
|
||||
api.send(query.answer(vec![])).await.ok();
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
let mut stream = query.query.chars().enumerate();
|
||||
while let Some((idx, letter)) = stream.next() {
|
||||
if idx % 2 == 0 {
|
||||
option1.push(letter.to_uppercase().next().unwrap());
|
||||
option2.push(letter.to_lowercase().next().unwrap());
|
||||
} else {
|
||||
option1.push(letter.to_lowercase().next().unwrap());
|
||||
option2.push(letter.to_uppercase().next().unwrap());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
api.send(query.answer(vec![
|
||||
InlineQueryResultArticle::new(
|
||||
"1", option1.clone(), InputTextMessageContent {
|
||||
message_text: option1,
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: false,
|
||||
}
|
||||
).into(),
|
||||
InlineQueryResultArticle::new(
|
||||
"2", option2.clone(), InputTextMessageContent {
|
||||
message_text: option2,
|
||||
parse_mode: None,
|
||||
disable_web_page_preview: false,
|
||||
}
|
||||
).into(),
|
||||
])).await.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user