fix some clippy complaints
This commit is contained in:
parent
cf8f2ec742
commit
cabd109554
1 changed files with 19 additions and 24 deletions
43
src/main.rs
43
src/main.rs
|
@ -2,7 +2,7 @@ use std::{
|
||||||
env,
|
env,
|
||||||
ffi::OsStr,
|
ffi::OsStr,
|
||||||
fs::{self, File, OpenOptions},
|
fs::{self, File, OpenOptions},
|
||||||
io::{self, Cursor, Read, Write},
|
io::{Cursor, Read, Write},
|
||||||
net::{Shutdown, TcpStream},
|
net::{Shutdown, TcpStream},
|
||||||
path::Path,
|
path::Path,
|
||||||
process::{self, Stdio},
|
process::{self, Stdio},
|
||||||
|
@ -72,7 +72,7 @@ impl Frame {
|
||||||
|
|
||||||
stream.connect().expect("api: connection failed");
|
stream.connect().expect("api: connection failed");
|
||||||
stream
|
stream
|
||||||
.write(
|
.write_all(
|
||||||
format!(
|
format!(
|
||||||
"PATCH /api/v10/channels/{}/messages/{message} HTTP/1.1\n",
|
"PATCH /api/v10/channels/{}/messages/{message} HTTP/1.1\n",
|
||||||
&self.channel
|
&self.channel
|
||||||
|
@ -81,19 +81,19 @@ impl Frame {
|
||||||
)
|
)
|
||||||
.expect("api: write failed");
|
.expect("api: write failed");
|
||||||
stream
|
stream
|
||||||
.write(
|
.write_all(
|
||||||
"Host: discord.com\nUser-Agent: projbot3 image uploader (tudbut@tudbut.de)\n"
|
"Host: discord.com\nUser-Agent: projbot3 image uploader (tudbut@tudbut.de)\n"
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)
|
)
|
||||||
.expect("api: write failed");
|
.expect("api: write failed");
|
||||||
stream
|
stream
|
||||||
.write(format!("Content-Length: {}\n", data.len()).as_bytes())
|
.write_all(format!("Content-Length: {}\n", data.len()).as_bytes())
|
||||||
.expect("api: write failed");
|
.expect("api: write failed");
|
||||||
stream
|
stream
|
||||||
.write(format!("Content-Type: {}\n", form.content_type_header()).as_bytes())
|
.write_all(format!("Content-Type: {}\n", form.content_type_header()).as_bytes())
|
||||||
.expect("api: write failed");
|
.expect("api: write failed");
|
||||||
stream
|
stream
|
||||||
.write(format!("Authorization: Bot {}\n\n", token).as_bytes())
|
.write_all(format!("Authorization: Bot {}\n\n", token).as_bytes())
|
||||||
.expect("api: write failed");
|
.expect("api: write failed");
|
||||||
|
|
||||||
// remove the last byte and cache it in the frame object for later write finish
|
// remove the last byte and cache it in the frame object for later write finish
|
||||||
|
@ -104,19 +104,19 @@ impl Frame {
|
||||||
);
|
);
|
||||||
data.remove(data.len() - 1);
|
data.remove(data.len() - 1);
|
||||||
|
|
||||||
stream.write(data.as_slice()).expect("api: write failed");
|
stream.write_all(data.as_slice()).expect("api: write failed");
|
||||||
|
|
||||||
self.cache_stream = Some(stream);
|
self.cache_stream = Some(stream);
|
||||||
// now the frame is ready to send the next part
|
// now the frame is ready to send the next part
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_send(&mut self) {
|
fn complete_send(&mut self) {
|
||||||
let ref mut cache_stream = self.cache_stream;
|
let cache_stream = &mut self.cache_stream;
|
||||||
let ref byte_to_write = self.byte_to_write;
|
let byte_to_write = &self.byte_to_write;
|
||||||
if let Some(stream) = cache_stream {
|
if let Some(stream) = cache_stream {
|
||||||
if let Some(byte) = byte_to_write {
|
if let Some(byte) = byte_to_write {
|
||||||
stream
|
stream
|
||||||
.write(&[*byte])
|
.write_all(&[*byte])
|
||||||
.expect("api: write failed at complete_send");
|
.expect("api: write failed at complete_send");
|
||||||
stream
|
stream
|
||||||
.get_ref()
|
.get_ref()
|
||||||
|
@ -142,9 +142,8 @@ 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");
|
let dir = fs::read_dir("vid_encoded").expect("unable to read dir").count();
|
||||||
let dir: Vec<_> = dir.collect();
|
for i in 0..dir {
|
||||||
for i in 0..dir.len() {
|
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.read(true)
|
.read(true)
|
||||||
.write(false)
|
.write(false)
|
||||||
|
@ -215,7 +214,7 @@ async fn send_frames(message: Message, ctx: Context) {
|
||||||
});
|
});
|
||||||
let mut sa = unix_millis();
|
let mut sa = unix_millis();
|
||||||
let mut to_compensate_for = 0;
|
let mut to_compensate_for = 0;
|
||||||
while let Some(mut frame) = v.next() {
|
for mut frame in v.by_ref() {
|
||||||
println!("vid: caching");
|
println!("vid: caching");
|
||||||
frame.cache_frame(
|
frame.cache_frame(
|
||||||
n.id.0,
|
n.id.0,
|
||||||
|
@ -233,8 +232,7 @@ async fn send_frames(message: Message, ctx: Context) {
|
||||||
sa = unix_millis();
|
sa = unix_millis();
|
||||||
if let Some(Ok(msg)) = msgs
|
if let Some(Ok(msg)) = msgs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| x.as_ref().unwrap().content == "!stop")
|
.find(|x| x.as_ref().unwrap().content == "!stop")
|
||||||
.next()
|
|
||||||
{
|
{
|
||||||
msg.delete(&ctx.http)
|
msg.delete(&ctx.http)
|
||||||
.await
|
.await
|
||||||
|
@ -243,8 +241,7 @@ async fn send_frames(message: Message, ctx: Context) {
|
||||||
}
|
}
|
||||||
if let Some(Ok(msg)) = msgs
|
if let Some(Ok(msg)) = msgs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| x.as_ref().unwrap().content == "!sync vid")
|
.find(|x| x.as_ref().unwrap().content == "!sync vid")
|
||||||
.next()
|
|
||||||
{
|
{
|
||||||
msg.delete(&ctx.http)
|
msg.delete(&ctx.http)
|
||||||
.await
|
.await
|
||||||
|
@ -260,8 +257,7 @@ async fn send_frames(message: Message, ctx: Context) {
|
||||||
}
|
}
|
||||||
if let Some(Ok(msg)) = msgs
|
if let Some(Ok(msg)) = msgs
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|x| x.as_ref().unwrap().content == "!sync aud")
|
.find(|x| x.as_ref().unwrap().content == "!sync aud")
|
||||||
.next()
|
|
||||||
{
|
{
|
||||||
msg.delete(&ctx.http)
|
msg.delete(&ctx.http)
|
||||||
.await
|
.await
|
||||||
|
@ -377,10 +373,9 @@ async fn main() {
|
||||||
.expect("encode: unable to move aud.opus to aud_encoded");
|
.expect("encode: unable to move aud.opus to aud_encoded");
|
||||||
|
|
||||||
fs::create_dir("vid_encoded").expect("encode: unable to modify files");
|
fs::create_dir("vid_encoded").expect("encode: unable to modify files");
|
||||||
let dir: Vec<_> = fs::read_dir("vid")
|
let dir = fs::read_dir("vid")
|
||||||
.expect("encode: unable to read files")
|
.expect("encode: unable to read files")
|
||||||
.collect();
|
.count();
|
||||||
let dir = dir.len();
|
|
||||||
let running = Arc::new(Mutex::new(0));
|
let running = Arc::new(Mutex::new(0));
|
||||||
println!("encode: encoding gifs...");
|
println!("encode: encoding gifs...");
|
||||||
for n in 0..((dir as f32 / (25.0 * 5.0)).ceil() as usize) {
|
for n in 0..((dir as f32 / (25.0 * 5.0)).ceil() as usize) {
|
||||||
|
@ -421,7 +416,7 @@ async fn main() {
|
||||||
.next_frame(&mut buf)
|
.next_frame(&mut buf)
|
||||||
.expect(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, &mut *bytes);
|
let mut frame = gif::Frame::from_rgb(240, 180, bytes);
|
||||||
frame.delay = 4;
|
frame.delay = 4;
|
||||||
encoder
|
encoder
|
||||||
.as_mut()
|
.as_mut()
|
||||||
|
|
Loading…
Add table
Reference in a new issue