mirror of
https://gitea.0xace.cc/rust/telegram-notifier.git
synced 2024-11-24 21:36:40 +00:00
move to frankenstein for telegram bot api
This commit is contained in:
parent
69689a6238
commit
59fa653889
1190
Cargo.lock
generated
1190
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,17 @@
|
||||
[package]
|
||||
name = "telegram-notifier"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
authors = ["ace <ace@0xace.cc>"]
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
frankenstein = { version = "0.26", default-features = false, features = ["async-http-client"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_yaml = "0.9"
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
clap = { version = "4", features = ["derive"] }
|
||||
telegram-bot = { git = "https://github.com/telegram-rs/telegram-bot", rev = "65ad5cfd578e9a1260ce6daac714eb2153c0bec7" }
|
||||
log = "0.4"
|
||||
stderrlog = "0.5"
|
||||
rand = "0.8"
|
||||
|
28
src/main.rs
28
src/main.rs
@ -1,11 +1,13 @@
|
||||
use serde_yaml;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use telegram_bot::*;
|
||||
use clap::Parser;
|
||||
use tokio;
|
||||
use log::*;
|
||||
use chrono::prelude::*;
|
||||
|
||||
use frankenstein;
|
||||
use frankenstein::AsyncApi;
|
||||
use frankenstein::AsyncTelegramApi;
|
||||
use frankenstein::SendMessageParams;
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize, Deserialize)]
|
||||
struct Config {
|
||||
@ -30,15 +32,16 @@ struct Opts {
|
||||
msg: String,
|
||||
/// Verbose level, accept multiple occurrences
|
||||
#[clap(short, long, action = clap::ArgAction::Count)]
|
||||
verbose: usize,
|
||||
verbose: u8,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let opts: Opts = Opts::parse();
|
||||
|
||||
stderrlog::new()
|
||||
.module(module_path!())
|
||||
.verbosity(opts.verbose)
|
||||
.verbosity(usize::from(opts.verbose))
|
||||
.timestamp(stderrlog::Timestamp::Second)
|
||||
.quiet(false)
|
||||
.init()
|
||||
@ -71,9 +74,18 @@ async fn telegram_notify(opts: &Opts, config: &Config) -> Result<(), Box<dyn std
|
||||
debug!("Using token: {}", config.token);
|
||||
println!("{} - LOG - Using chat id: {}", Local::now().trunc_subsecs(0).to_rfc3339(), config.chatid);
|
||||
println!("{} - LOG - {}", Local::now().trunc_subsecs(0).to_rfc3339(), opts.msg);
|
||||
let api = Api::new(&config.token);
|
||||
let chat = ChatId::new(config.chatid);
|
||||
let msg = Local::now().format("%Y-%m-%d %H:%M:%S: ").to_string() + &opts.msg.to_string();
|
||||
let _ = api.send(chat.text(msg)).await?;
|
||||
|
||||
let api = AsyncApi::new(&config.token);
|
||||
|
||||
let str = Local::now().format("%Y-%m-%d %H:%M:%S: ").to_string() + &opts.msg.to_string();
|
||||
let send_message_params: SendMessageParams = SendMessageParams::builder()
|
||||
.chat_id(config.chatid)
|
||||
.text(str)
|
||||
.build();
|
||||
|
||||
if let Err(err) = api.send_message(&send_message_params).await {
|
||||
println!("Failed to send message: {err:?}");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user