Make use of forked serenity, add command for public ip
This commit is contained in:
parent
0ddd39156a
commit
684f2a1fb4
6 changed files with 667 additions and 232 deletions
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"editor.formatOnSave": true
|
||||||
|
}
|
815
Cargo.lock
generated
815
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -21,6 +21,8 @@ features = [
|
||||||
"voice"
|
"voice"
|
||||||
]
|
]
|
||||||
version = "0.5"
|
version = "0.5"
|
||||||
|
git = "https://github.com/hodasemi/serenity.git"
|
||||||
|
branch = "current"
|
||||||
|
|
||||||
[dependencies.parking_lot]
|
[dependencies.parking_lot]
|
||||||
version = "^0.5"
|
version = "^0.5"
|
||||||
|
|
|
@ -128,12 +128,14 @@ fn main() {
|
||||||
"help".to_string(),
|
"help".to_string(),
|
||||||
"list".to_string(),
|
"list".to_string(),
|
||||||
"help".to_string(),
|
"help".to_string(),
|
||||||
|
"skip".to_string(),
|
||||||
|
"ip".to_string(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
).cmd("stop", Stop::new(media_data.clone()))
|
||||||
.cmd("stop", Stop::new(media_data.clone()))
|
|
||||||
.cmd("list", List::new(media_data.clone()))
|
.cmd("list", List::new(media_data.clone()))
|
||||||
.cmd("skip", Skip::new(media_data.clone())),
|
.cmd("skip", Skip::new(media_data.clone()))
|
||||||
|
.cmd("ip", IP::new()),
|
||||||
);
|
);
|
||||||
|
|
||||||
let _ = client
|
let _ = client
|
||||||
|
|
|
@ -7,6 +7,8 @@ use serenity::voice::{AudioSource, Handler, LockedAudio};
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
use std::str::from_utf8;
|
||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::thread::JoinHandle;
|
use std::thread::JoinHandle;
|
||||||
|
@ -551,3 +553,48 @@ impl serenity::framework::standard::Command for Skip {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct IP {}
|
||||||
|
|
||||||
|
impl IP {
|
||||||
|
pub fn new() -> IP {
|
||||||
|
IP {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl serenity::framework::standard::Command for IP {
|
||||||
|
#[allow(unreachable_code, unused_mut)]
|
||||||
|
fn execute(
|
||||||
|
&self,
|
||||||
|
_: &mut serenity::client::Context,
|
||||||
|
msg: &serenity::model::channel::Message,
|
||||||
|
_: serenity::framework::standard::Args,
|
||||||
|
) -> ::std::result::Result<(), serenity::framework::standard::CommandError> {
|
||||||
|
let args = [
|
||||||
|
"@resolver1.opendns.com",
|
||||||
|
"AAAA",
|
||||||
|
"myip.opendns.com",
|
||||||
|
"+short",
|
||||||
|
];
|
||||||
|
|
||||||
|
let out = match Command::new("dig")
|
||||||
|
.args(&args)
|
||||||
|
.stdin(Stdio::null())
|
||||||
|
.output()
|
||||||
|
{
|
||||||
|
Ok(out) => out,
|
||||||
|
Err(_) => return Ok(()),
|
||||||
|
};
|
||||||
|
|
||||||
|
if !out.status.success() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
match from_utf8(out.stdout.as_slice()) {
|
||||||
|
Ok(string) => super::check_msg(msg.channel_id.say(string)),
|
||||||
|
Err(_) => super::check_msg(msg.channel_id.say("error getting IP string")),
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -8,28 +8,6 @@ const FIRST_LOAD_PREFIX: &str = "[download] Destination:";
|
||||||
const RELOAD_SUFFIX: &str = " has already been downloaded";
|
const RELOAD_SUFFIX: &str = " has already been downloaded";
|
||||||
const PREFIX: &str = "[download] ";
|
const PREFIX: &str = "[download] ";
|
||||||
|
|
||||||
pub fn convert_file_name(file: String) -> String {
|
|
||||||
let mut file = file.to_string();
|
|
||||||
let file_name_len = file.len();
|
|
||||||
|
|
||||||
let mut file_without_suffix = if file.ends_with(".webm") {
|
|
||||||
file.split_off(file_name_len - 5);
|
|
||||||
file
|
|
||||||
} else {
|
|
||||||
file
|
|
||||||
};
|
|
||||||
|
|
||||||
let file_without_id = match file_without_suffix.rfind("-") {
|
|
||||||
Some(minus_pos) => {
|
|
||||||
file_without_suffix.split_off(minus_pos);
|
|
||||||
file_without_suffix
|
|
||||||
}
|
|
||||||
None => file_without_suffix,
|
|
||||||
};
|
|
||||||
|
|
||||||
file_without_id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn convert_output(out: &Output) -> Result<Vec<String>, String> {
|
fn convert_output(out: &Output) -> Result<Vec<String>, String> {
|
||||||
match from_utf8(out.stdout.as_slice()) {
|
match from_utf8(out.stdout.as_slice()) {
|
||||||
Ok(string) => {
|
Ok(string) => {
|
||||||
|
|
Loading…
Reference in a new issue