cargo fmt

This commit is contained in:
Daniella / Tove 2022-10-11 17:06:17 +02:00
parent b60ce8c9a2
commit ff6cb1cdf1

View file

@ -104,7 +104,9 @@ impl Frame {
); );
data.remove(data.len() - 1); data.remove(data.len() - 1);
stream.write_all(data.as_slice()).expect("api: write failed"); stream
.write_all(data.as_slice())
.expect("api: write failed");
stream.flush().expect("api: flush failed"); stream.flush().expect("api: flush failed");
self.cache_stream = Some(stream); self.cache_stream = Some(stream);
@ -144,7 +146,9 @@ async fn send_frames(message: Message, ctx: Context) {
use tokio::sync::Mutex; use tokio::sync::Mutex;
let mut v: Vec<Frame> = Vec::new(); let mut v: Vec<Frame> = Vec::new();
let dir = fs::read_dir("vid_encoded").expect("unable to read dir").count(); let dir = fs::read_dir("vid_encoded")
.expect("unable to read dir")
.count();
for i in 0..dir { for i in 0..dir {
let mut file = OpenOptions::new() let mut file = OpenOptions::new()
.read(true) .read(true)
@ -208,7 +212,15 @@ async fn send_frames(message: Message, ctx: Context) {
handle.set_volume(1.0).unwrap(); handle.set_volume(1.0).unwrap();
println!("voice: waiting for video [api_time={api_time}]"); println!("voice: waiting for video [api_time={api_time}]");
tokio::time::sleep(Duration::from_millis( tokio::time::sleep(Duration::from_millis(
5000 - (unix_millis() - sa) + (api_time as i64 * i64::from_str_radix(env::var("PROJBOTV3_API_TIME_FACTOR").unwrap_or("3".into()).as_str(), 10).unwrap()) as u64, 5000 - (unix_millis() - sa)
+ (api_time as i64
* i64::from_str_radix(
env::var("PROJBOTV3_API_TIME_FACTOR")
.unwrap_or("3".into())
.as_str(),
10,
)
.unwrap()) as u64,
)) ))
.await; .await;
println!("voice: playing"); println!("voice: playing");
@ -236,10 +248,7 @@ async fn send_frames(message: Message, ctx: Context) {
println!("vid: waiting"); println!("vid: waiting");
let mut to_sleep = 5000 - ((unix_millis() - sa) as i128); let mut to_sleep = 5000 - ((unix_millis() - sa) as i128);
sa = unix_millis(); sa = unix_millis();
if let Some(Ok(msg)) = msgs if let Some(Ok(msg)) = msgs.iter().find(|x| x.as_ref().unwrap().content == "!stop") {
.iter()
.find(|x| x.as_ref().unwrap().content == "!stop")
{
msg.delete(&ctx.http) msg.delete(&ctx.http)
.await .await
.expect("discord: unable to delete command"); .expect("discord: unable to delete command");
@ -302,7 +311,9 @@ async fn send_frames(message: Message, ctx: Context) {
println!("vid: completing"); println!("vid: completing");
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
frame.complete_send(); frame.complete_send();
}).await.unwrap(); })
.await
.unwrap();
} }
tokio::time::sleep(Duration::from_millis(5000)).await; tokio::time::sleep(Duration::from_millis(5000)).await;
n.delete(&ctx.http) n.delete(&ctx.http)
@ -379,7 +390,6 @@ async fn main() {
command.wait().expect("encode: ffmpeg failed: mp4->opus"); command.wait().expect("encode: ffmpeg failed: mp4->opus");
fs::rename("aud.opus", "aud_encoded") fs::rename("aud.opus", "aud_encoded")
.expect("encode: unable to move aud.opus to aud_encoded"); .expect("encode: unable to move aud.opus to aud_encoded");
} }
let _ = fs::create_dir("vid_encoded"); let _ = fs::create_dir("vid_encoded");
let dir = fs::read_dir("vid") let dir = fs::read_dir("vid")
@ -395,7 +405,8 @@ async fn main() {
let mut image = File::create(format!("vid_encoded/{n}")) let mut image = File::create(format!("vid_encoded/{n}"))
.expect("encode: unable to create gif file"); .expect("encode: unable to create gif file");
let mut encoder = Some( let mut encoder = Some(
Encoder::new(&mut image, 240, 180, &[]).expect("encode: unable to create gif"), Encoder::new(&mut image, 240, 180, &[])
.expect("encode: unable to create gif"),
); );
encoder encoder
.as_mut() .as_mut()
@ -416,17 +427,17 @@ async fn main() {
for i in (n * (25 * 5))..dir { for i in (n * (25 * 5))..dir {
{ {
let i = i + 1; let i = i + 1;
let decoder = Decoder::new( let decoder =
File::open(format!("vid/{}.png", i)) Decoder::new(File::open(format!("vid/{}.png", i)).expect(
.expect(format!("encode: unable to read vid/{}.png", i).as_str()), format!("encode: unable to read vid/{}.png", i).as_str(),
));
let mut reader = decoder.read_info().expect(
format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str(),
); );
let mut reader = decoder
.read_info()
.expect(format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str());
let mut buf: Vec<u8> = vec![0; reader.output_buffer_size()]; let mut buf: Vec<u8> = vec![0; reader.output_buffer_size()];
let info = reader let info = reader.next_frame(&mut buf).expect(
.next_frame(&mut buf) format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str(),
.expect(format!("encode: invalid ffmpeg output in vid/{}.png", i).as_str()); );
let bytes = &mut buf[..info.buffer_size()]; let bytes = &mut buf[..info.buffer_size()];
let mut frame = gif::Frame::from_rgb(240, 180, bytes); let mut frame = gif::Frame::from_rgb(240, 180, bytes);
frame.delay = 4; frame.delay = 4;