Skip to content

Commit 52469b9

Browse files
cargo fmt
1 parent 4f7551a commit 52469b9

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

.githooks/pre-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
set -eo pipefail
33

44
# make sure I didn't forget to run rustfmt
5-
cargo fmt --all -- --check -l || ( echo -e "\e[1mYou need to run 'cargo fmt' first\e[0m" && false )
5+
cargo +nightly fmt --all -- --check -l || ( echo -e "\e[1mYou need to run 'cargo fmt' first\e[0m" && false )

src/main.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
fs::{self, File},
1313
io::{self, BufRead, Write},
1414
path::Path,
15-
process::exit
15+
process::exit,
1616
};
1717
use structopt::StructOpt;
1818
use tempfile::NamedTempFile;
@@ -38,31 +38,31 @@ struct OptImport {
3838
/// Do not format the stickers;
3939
/// The stickers can may not be shown by a matrix client
4040
#[structopt(short = "F", long)]
41-
noformat: bool
41+
noformat: bool,
4242
}
4343

4444
#[derive(Debug, StructOpt)]
4545
enum Opt {
4646
/// import Stickerpack from telegram
47-
Import(OptImport)
47+
Import(OptImport),
4848
}
4949

5050
#[derive(Deserialize)]
5151
struct Matrix {
5252
homeserver_url: String,
5353
user: String,
54-
access_token: String
54+
access_token: String,
5555
}
5656

5757
#[derive(Deserialize)]
5858
struct TTelegram {
59-
bot_key: String
59+
bot_key: String,
6060
}
6161

6262
#[derive(Deserialize)]
6363
struct TomlFile {
6464
telegram: TTelegram,
65-
matrix: Matrix
65+
matrix: Matrix,
6666
}
6767

6868
// TODO rename to Status
@@ -71,46 +71,46 @@ struct TJsonState {
7171
ok: bool,
7272

7373
error_code: Option<u32>,
74-
description: Option<String>
74+
description: Option<String>,
7575
}
7676

7777
#[derive(Debug)]
7878
struct MSticker {
7979
filename: String,
8080
mimetype: String,
81-
uri: String
81+
uri: String,
8282
}
8383

8484
#[derive(Debug, Deserialize)]
8585
struct TJsonSticker {
8686
emoji: String,
87-
file_id: String
87+
file_id: String,
8888
}
8989

9090
#[derive(Debug, Deserialize)]
9191
struct TJsonStickerPack {
9292
name: String,
9393
title: String,
9494
is_animated: bool,
95-
stickers: Vec<TJsonSticker>
95+
stickers: Vec<TJsonSticker>,
9696
}
9797

9898
#[derive(Debug, Deserialize)]
9999
struct TJsonFile {
100-
file_path: String
100+
file_path: String,
101101
}
102102

103103
#[derive(Debug, Deserialize, Serialize)]
104104
struct HashUrl {
105105
hash: GenericArray<u8, <Sha512 as Digest>::OutputSize>,
106-
url: String
106+
url: String,
107107
}
108108

109109
#[derive(Debug, Deserialize)]
110110
struct MatrixError {
111111
errcode: String,
112112
error: String,
113-
_retry_after_ms: Option<u32>
113+
_retry_after_ms: Option<u32>,
114114
}
115115

116116
fn check_telegram_resp(mut resp: serde_json::Value) -> anyhow::Result<serde_json::Value> {
@@ -137,7 +137,7 @@ fn upload_to_matrix(matrix: &Matrix, filename: String, image_data: Vec<u8>, mime
137137
.ok_or_else(|| anyhow!("ERROR: extracting mimetype from path {}", filename))?
138138
.to_str()
139139
.ok_or_else(|| anyhow!("ERROR: converting mimetype to string"))?
140-
)
140+
),
141141
};
142142
let answer = attohttpc::put(url)
143143
.params([("access_token", &matrix.access_token), ("filename", &filename)])
@@ -167,7 +167,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
167167
"Failed to open {}",
168168
PROJECT_DIRS.config_dir().join(CONFIG_FILE).to_str().unwrap()
169169
)
170-
})?
170+
})?,
171171
)?;
172172
let telegram_api_base_url = format!("https://api.telegram.org/bot{}", toml_file.telegram.bot_key);
173173
check_telegram_resp(attohttpc::get(format!("{}/getMe", telegram_api_base_url)).send()?.json()?)?;
@@ -176,7 +176,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
176176
attohttpc::get(format!("{}/getStickerSet", telegram_api_base_url))
177177
.param("name", &opt.pack)
178178
.send()?
179-
.json()?
179+
.json()?,
180180
)?)?;
181181
println!("found Telegram stickerpack {}({})", stickerpack.title, stickerpack.name);
182182
if opt.download {
@@ -198,7 +198,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
198198
i + 1,
199199
database_file.as_path().display(),
200200
error
201-
)
201+
),
202202
};
203203
}
204204
},
@@ -207,7 +207,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
207207
},
208208
Err(error) => {
209209
return Err(error.into());
210-
}
210+
},
211211
};
212212
let database = fs::OpenOptions::new()
213213
.write(true)
@@ -220,7 +220,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
220220
Err(error) => {
221221
eprintln!("{:?}", error);
222222
None
223-
}
223+
},
224224
};
225225
stickerpack
226226
.stickers
@@ -238,7 +238,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
238238
attohttpc::get(format!("{}/getFile", telegram_api_base_url))
239239
.param("file_id", &sticker.file_id)
240240
.send()?
241-
.json()?
241+
.json()?,
242242
)?)?;
243243
let mut sticker_image = attohttpc::get(format!(
244244
"https://api.telegram.org/file/bot{}/{}",
@@ -265,9 +265,9 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
265265
r: 0,
266266
g: 0,
267267
b: 0,
268-
alpha: true
268+
alpha: true,
269269
},
270-
&mut sticker_image
270+
&mut sticker_image,
271271
)?;
272272
sticker_file.file_path += ".gif";
273273
}
@@ -278,7 +278,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
278278
let file_path: &Path = sticker_file.file_path.as_ref();
279279
fs::write(
280280
Path::new(&format!("./stickers/{}", stickerpack.name)).join(file_path.file_name().unwrap()),
281-
&sticker_image
281+
&sticker_image,
282282
)?;
283283
}
284284
/*if !opt.noupload && database.is_some() {
@@ -323,7 +323,7 @@ fn main() {
323323
exit(1);
324324
}
325325
let result = match Opt::from_args() {
326-
Opt::Import(opt) => import(opt)
326+
Opt::Import(opt) => import(opt),
327327
};
328328
if let Err(error) = result {
329329
eprintln!("{:?}", error);

0 commit comments

Comments
 (0)