Skip to content

top-tl/teloxide

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

toptl-teloxide

Teloxide plugin for TOP.TL — auto-post bot stats and check votes.

Installation

[dependencies]
toptl-teloxide = "1.0"

Quick start

use teloxide::prelude::*;
use toptl::TopTLClient;
use toptl_teloxide::{TopTLPlugin, record_update};

#[tokio::main]
async fn main() {
    let client = TopTLClient::new("your-api-token");
    let plugin = TopTLPlugin::new(client, "mybot");
    plugin.start(); // spawns background stats posting

    let bot = Bot::from_env();

    teloxide::repl(bot, move |msg: Message| {
        let plugin = plugin.clone();
        async move {
            record_update(&plugin, &msg).await;
            // ... your handler logic
            respond(())
        }
    })
    .await;
}

Vote-gating

async fn premium_command(plugin: &TopTLPlugin, msg: &Message, bot: &Bot) {
    let user_id = msg.from.as_ref().map(|u| u.id.0 as i64).unwrap_or(0);
    if !plugin.has_voted(user_id).await {
        bot.send_message(msg.chat.id, "Please vote first: https://top.tl/mybot").await?;
        return Ok(());
    }
    bot.send_message(msg.chat.id, "Thanks for voting!").await?;
    Ok(())
}

How it works

  • Trackingrecord_update (or manual record) stores unique user, group, and channel IDs.
  • Auto-postingstart() spawns a tokio task that posts stats at a server-controlled interval.
  • Vote checkshas_voted(user_id) queries the TOP.TL API.

License

MIT

About

Teloxide plugin for TOP.TL — auto-post bot stats & check votes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages