move all config into config.toml
This commit is contained in:
2
build_musl
Executable file
2
build_musl
Executable file
@@ -0,0 +1,2 @@
|
|||||||
|
alias rust-musl-builder='sudo docker run --rm -it -v "$(pwd)":/home/rust/src ekidd/rust-musl-builder'
|
||||||
|
rust-musl-builder cargo build --release
|
||||||
18
src/main.rs
18
src/main.rs
@@ -1,12 +1,13 @@
|
|||||||
mod mindus;
|
mod mindus;
|
||||||
use crate::mindus::*;
|
use crate::mindus::*;
|
||||||
use std::{env};
|
// use std::{env};
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::framework::standard::macros::{command, group};
|
use serenity::framework::standard::macros::{command, group};
|
||||||
use serenity::framework::standard::{StandardFramework, CommandResult};
|
use serenity::framework::standard::{StandardFramework, CommandResult};
|
||||||
use dotenv::dotenv;
|
|
||||||
|
|
||||||
|
|
||||||
#[group]
|
#[group]
|
||||||
#[commands(ping, pong, console)]
|
#[commands(ping, pong, console)]
|
||||||
@@ -23,15 +24,14 @@ async fn main() {
|
|||||||
|
|
||||||
let sock = TcpSock::new(conf.ip, conf.port).unwrap();
|
let sock = TcpSock::new(conf.ip, conf.port).unwrap();
|
||||||
|
|
||||||
dotenv().ok();
|
|
||||||
|
|
||||||
let framework = StandardFramework::new()
|
let framework = StandardFramework::new()
|
||||||
.configure(|c| c.prefix(conf.trigger))
|
.configure(|c| c
|
||||||
|
.prefix(conf.trigger)
|
||||||
|
.case_insensitivity(true))
|
||||||
.group(&GENERAL_GROUP);
|
.group(&GENERAL_GROUP);
|
||||||
|
|
||||||
let token = env::var("DISCORD_TOKEN").expect("token");
|
|
||||||
let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;
|
let intents = GatewayIntents::non_privileged() | GatewayIntents::MESSAGE_CONTENT;
|
||||||
let mut client = Client::builder(&token, intents)
|
let mut client = Client::builder(&conf.discord_token, intents)
|
||||||
.event_handler(Handler)
|
.event_handler(Handler)
|
||||||
.framework(framework)
|
.framework(framework)
|
||||||
.await
|
.await
|
||||||
@@ -49,8 +49,8 @@ async fn main() {
|
|||||||
|
|
||||||
#[command]
|
#[command]
|
||||||
async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
async fn ping(ctx: &Context, msg: &Message) -> CommandResult {
|
||||||
|
|
||||||
msg.reply(ctx, "Pong!").await?;
|
msg.reply(ctx, "Pong!").await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ async fn console(ctx: &Context, msg: &Message) -> CommandResult {
|
|||||||
|
|
||||||
let sock = data.get::<TcpSock>().unwrap();
|
let sock = data.get::<TcpSock>().unwrap();
|
||||||
|
|
||||||
msg.reply(ctx, format!("```ansi\n{}\n```", cons_rw(sock, &input.unwrap()))).await?;
|
msg.reply(ctx, format!("```\n{}\n```", cons_rw(sock, &input.unwrap()))).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,10 +45,18 @@ pub fn cons_rw(sock: &TcpSock, input: &str) -> String {
|
|||||||
|
|
||||||
#[derive(serde::Deserialize, serde::Serialize)]
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
pub discord_token: String,
|
||||||
pub ip: String,
|
pub ip: String,
|
||||||
pub port: String,
|
pub port: String,
|
||||||
pub trigger: char,
|
pub trigger: char,
|
||||||
pub roles: String
|
pub roles: Roles
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Roles {
|
||||||
|
pub auth: String,
|
||||||
|
pub cons: String
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn init_conf() -> Config {
|
pub fn init_conf() -> Config {
|
||||||
@@ -68,12 +76,6 @@ pub fn init_conf() -> Config {
|
|||||||
|
|
||||||
let config: Config = toml::from_str(&toml_str).expect("unable to fill Config struct");
|
let config: Config = toml::from_str(&toml_str).expect("unable to fill Config struct");
|
||||||
|
|
||||||
// let mut conf_vec: Vec<u8> = vec![];
|
|
||||||
// toml_file.read_to_end(&mut conf_vec).expect("unable to read toml to string");
|
|
||||||
// let toml_str = str::from_utf8(&conf_vec).expect("unable to convert to string");
|
|
||||||
// println!("{}", toml_str);
|
|
||||||
// let config: Config = toml::from_str(toml_str).expect("unable to fill Config struct");
|
|
||||||
|
|
||||||
config
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,10 +89,14 @@ let mut toml_file = OpenOptions::new()
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let fill_conf = Config {
|
let fill_conf = Config {
|
||||||
|
discord_token: String::from(""),
|
||||||
ip: String::from("localhost"),
|
ip: String::from("localhost"),
|
||||||
port: String::from("6859"),
|
port: String::from("6859"),
|
||||||
trigger: ';',
|
trigger: ';',
|
||||||
roles: String::new()
|
roles: Roles {
|
||||||
|
auth: String::from(""),
|
||||||
|
cons: String::from("")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
toml_file.write(toml::to_string(&fill_conf).unwrap().as_bytes()).expect("Unable to write to new file");
|
toml_file.write(toml::to_string(&fill_conf).unwrap().as_bytes()).expect("Unable to write to new file");
|
||||||
|
|||||||
Reference in New Issue
Block a user