@@ -12,7 +12,7 @@ use std::{
12
12
fs:: { self , File } ,
13
13
io:: { self , BufRead , Write } ,
14
14
path:: Path ,
15
- process:: exit
15
+ process:: exit,
16
16
} ;
17
17
use structopt:: StructOpt ;
18
18
use tempfile:: NamedTempFile ;
@@ -38,31 +38,31 @@ struct OptImport {
38
38
/// Do not format the stickers;
39
39
/// The stickers can may not be shown by a matrix client
40
40
#[ structopt( short = "F" , long) ]
41
- noformat : bool
41
+ noformat : bool ,
42
42
}
43
43
44
44
#[ derive( Debug , StructOpt ) ]
45
45
enum Opt {
46
46
/// import Stickerpack from telegram
47
- Import ( OptImport )
47
+ Import ( OptImport ) ,
48
48
}
49
49
50
50
#[ derive( Deserialize ) ]
51
51
struct Matrix {
52
52
homeserver_url : String ,
53
53
user : String ,
54
- access_token : String
54
+ access_token : String ,
55
55
}
56
56
57
57
#[ derive( Deserialize ) ]
58
58
struct TTelegram {
59
- bot_key : String
59
+ bot_key : String ,
60
60
}
61
61
62
62
#[ derive( Deserialize ) ]
63
63
struct TomlFile {
64
64
telegram : TTelegram ,
65
- matrix : Matrix
65
+ matrix : Matrix ,
66
66
}
67
67
68
68
// TODO rename to Status
@@ -71,46 +71,46 @@ struct TJsonState {
71
71
ok : bool ,
72
72
73
73
error_code : Option < u32 > ,
74
- description : Option < String >
74
+ description : Option < String > ,
75
75
}
76
76
77
77
#[ derive( Debug ) ]
78
78
struct MSticker {
79
79
filename : String ,
80
80
mimetype : String ,
81
- uri : String
81
+ uri : String ,
82
82
}
83
83
84
84
#[ derive( Debug , Deserialize ) ]
85
85
struct TJsonSticker {
86
86
emoji : String ,
87
- file_id : String
87
+ file_id : String ,
88
88
}
89
89
90
90
#[ derive( Debug , Deserialize ) ]
91
91
struct TJsonStickerPack {
92
92
name : String ,
93
93
title : String ,
94
94
is_animated : bool ,
95
- stickers : Vec < TJsonSticker >
95
+ stickers : Vec < TJsonSticker > ,
96
96
}
97
97
98
98
#[ derive( Debug , Deserialize ) ]
99
99
struct TJsonFile {
100
- file_path : String
100
+ file_path : String ,
101
101
}
102
102
103
103
#[ derive( Debug , Deserialize , Serialize ) ]
104
104
struct HashUrl {
105
105
hash : GenericArray < u8 , <Sha512 as Digest >:: OutputSize > ,
106
- url : String
106
+ url : String ,
107
107
}
108
108
109
109
#[ derive( Debug , Deserialize ) ]
110
110
struct MatrixError {
111
111
errcode : String ,
112
112
error : String ,
113
- _retry_after_ms : Option < u32 >
113
+ _retry_after_ms : Option < u32 > ,
114
114
}
115
115
116
116
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
137
137
. ok_or_else( || anyhow!( "ERROR: extracting mimetype from path {}" , filename) ) ?
138
138
. to_str( )
139
139
. ok_or_else( || anyhow!( "ERROR: converting mimetype to string" ) ) ?
140
- )
140
+ ) ,
141
141
} ;
142
142
let answer = attohttpc:: put ( url)
143
143
. params ( [ ( "access_token" , & matrix. access_token ) , ( "filename" , & filename) ] )
@@ -167,7 +167,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
167
167
"Failed to open {}" ,
168
168
PROJECT_DIRS . config_dir( ) . join( CONFIG_FILE ) . to_str( ) . unwrap( )
169
169
)
170
- } ) ?
170
+ } ) ?,
171
171
) ?;
172
172
let telegram_api_base_url = format ! ( "https://api.telegram.org/bot{}" , toml_file. telegram. bot_key) ;
173
173
check_telegram_resp ( attohttpc:: get ( format ! ( "{}/getMe" , telegram_api_base_url) ) . send ( ) ?. json ( ) ?) ?;
@@ -176,7 +176,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
176
176
attohttpc:: get ( format ! ( "{}/getStickerSet" , telegram_api_base_url) )
177
177
. param ( "name" , & opt. pack )
178
178
. send ( ) ?
179
- . json ( ) ?
179
+ . json ( ) ?,
180
180
) ?) ?;
181
181
println ! ( "found Telegram stickerpack {}({})" , stickerpack. title, stickerpack. name) ;
182
182
if opt. download {
@@ -198,7 +198,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
198
198
i + 1 ,
199
199
database_file. as_path( ) . display( ) ,
200
200
error
201
- )
201
+ ) ,
202
202
} ;
203
203
}
204
204
} ,
@@ -207,7 +207,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
207
207
} ,
208
208
Err ( error) => {
209
209
return Err ( error. into ( ) ) ;
210
- }
210
+ } ,
211
211
} ;
212
212
let database = fs:: OpenOptions :: new ( )
213
213
. write ( true )
@@ -220,7 +220,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
220
220
Err ( error) => {
221
221
eprintln ! ( "{:?}" , error) ;
222
222
None
223
- }
223
+ } ,
224
224
} ;
225
225
stickerpack
226
226
. stickers
@@ -238,7 +238,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
238
238
attohttpc:: get ( format ! ( "{}/getFile" , telegram_api_base_url) )
239
239
. param ( "file_id" , & sticker. file_id )
240
240
. send ( ) ?
241
- . json ( ) ?
241
+ . json ( ) ?,
242
242
) ?) ?;
243
243
let mut sticker_image = attohttpc:: get ( format ! (
244
244
"https://api.telegram.org/file/bot{}/{}" ,
@@ -265,9 +265,9 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
265
265
r : 0 ,
266
266
g : 0 ,
267
267
b : 0 ,
268
- alpha : true
268
+ alpha : true ,
269
269
} ,
270
- & mut sticker_image
270
+ & mut sticker_image,
271
271
) ?;
272
272
sticker_file. file_path += ".gif" ;
273
273
}
@@ -278,7 +278,7 @@ fn import(opt: OptImport) -> anyhow::Result<()> {
278
278
let file_path: & Path = sticker_file. file_path . as_ref ( ) ;
279
279
fs:: write (
280
280
Path :: new ( & format ! ( "./stickers/{}" , stickerpack. name) ) . join ( file_path. file_name ( ) . unwrap ( ) ) ,
281
- & sticker_image
281
+ & sticker_image,
282
282
) ?;
283
283
}
284
284
/*if !opt.noupload && database.is_some() {
@@ -323,7 +323,7 @@ fn main() {
323
323
exit ( 1 ) ;
324
324
}
325
325
let result = match Opt :: from_args ( ) {
326
- Opt :: Import ( opt) => import ( opt)
326
+ Opt :: Import ( opt) => import ( opt) ,
327
327
} ;
328
328
if let Err ( error) = result {
329
329
eprintln ! ( "{:?}" , error) ;
0 commit comments