Last active
January 22, 2019 14:40
-
-
Save SnejUgal/ecc4d94ecca83c36a9417b62b330324b to your computer and use it in GitHub Desktop.
Extract default wallpapers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// First you should prepare all themes with default wallpapers using | |
// tdesktop. Go to Settings -> Chat Settings -> Choose from gallery, | |
// choose a wallpaper, go back -> Launch theme editor -> ... -> Export | |
// theme -> Export, and name it `n.tdesktop-theme` where n is an | |
// inremeneted counter. Repeat for all wallpapers. | |
// Specify the last value of `n` here | |
const N: u8 = 1; | |
// Specify the channel where the wallpapers will be sent | |
const CHANNEL: &str = "@defaultwallpapers"; | |
use tbot::{ | |
prelude::*, | |
types::{Document, Photo}, | |
Bot, | |
}; | |
use tdesktop_theme::TdesktopTheme; | |
fn main() { | |
let bot = &Bot::from_env("BOT_TOKEN"); | |
for nth in 1..=N { | |
let picture = TdesktopTheme::from_bytes( | |
&std::fs::read(format!("./{}.tdesktop-theme", nth)) | |
.unwrap_or_else(|_| { | |
panic!("theme {} does not exist", nth); | |
}), | |
) | |
.unwrap_or_else(|_| { | |
panic!("theme {} is invalid valid", nth); | |
}) | |
.wallpaper | |
.unwrap_or_else(|| { | |
panic!("theme {} has no wallpaper", nth); | |
}) | |
.bytes; | |
let mock = bot.mock(); | |
let preview = bot | |
.send_photo(CHANNEL, Photo::bytes(&picture)) | |
.into_future() | |
.map_err(|error| { | |
dbg!(error); | |
}) | |
// Parsing of the response fails atm, so an error is | |
// returned though everything is actually okay. Once this | |
// is fixed, change it to `and_then` | |
.or_else(move |_| { | |
mock.send_document( | |
CHANNEL, | |
Document::bytes("wallpaper.jpg", &picture), | |
) | |
.into_future() | |
}) | |
.map_err(|error| { | |
dbg!(error); | |
}); | |
tbot::run(preview); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment