1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyleft (ɔ) 2021-2021 Fuwn
// SPDX-License-Identifier: GPL-3.0-only
use std::{
fs::{create_dir, File},
io::{BufRead, Write},
};
use rand::Rng;
pub struct Nitrous;
impl Nitrous {
pub async fn execute() {
// Environment
dotenv::dotenv().ok();
std::env::set_var("RUST_LOG", "nitrous=trace");
// Logging
pretty_env_logger::init();
crate::cli::Cli::execute().await;
}
fn initialize() { let _ = create_dir("nitrous"); }
pub fn generate(amount: usize, debug: bool) {
Self::initialize();
let mut codes = File::create("nitrous/codes.txt").unwrap();
for _ in 0..amount {
let code = rand::thread_rng()
.sample_iter(rand::distributions::Alphanumeric)
.take(16)
.map(char::from)
.collect::<String>();
writeln!(codes, "{}", code).unwrap();
if debug {
info!("{}", code,);
}
}
}
pub async fn check(codes_file_name: &str, debug: bool) {
Self::initialize();
let _ = create_dir("nitrous/check/");
let codes = File::open(codes_file_name).unwrap();
let mut invalid = File::create("nitrous/check/invalid.txt").unwrap();
let mut valid = File::create("nitrous/check/valid.txt").unwrap();
for code in std::io::BufReader::new(codes).lines() {
let code = code.unwrap();
let status = reqwest::get(format!(
"https://discordapp.com/api/v6/entitlements/gift-codes/{}?with_applica\
tion=false&with_subscription_plan=true",
code
))
.await
.unwrap()
.status()
.as_u16();
if status == 200 {
writeln!(valid, "{}", code).unwrap();
if debug {
info!("{}", code);
}
} else {
writeln!(invalid, "{}", code).unwrap();
if debug {
error!("{}", code);
}
}
}
}
}
|