src
This commit is contained in:
99
src/main.rs
99
src/main.rs
@@ -2,12 +2,14 @@ mod mindus;
|
||||
use crate::mindus::*;
|
||||
// use std::{env};
|
||||
use serenity::async_trait;
|
||||
use serenity::model::prelude::{UserId};
|
||||
use serenity::model::prelude::{UserId, RoleId};
|
||||
use serenity::prelude::*;
|
||||
use serenity::model::channel::Message;
|
||||
use serenity::framework::standard::macros::{command, group, help, hook};
|
||||
use serenity::framework::standard::{StandardFramework, CommandResult, Args, HelpOptions, CommandGroup, help_commands};
|
||||
use serenity::utils::Color;
|
||||
use std::collections::HashSet;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[group]
|
||||
#[commands(ping, pong, console, git, discord)]
|
||||
@@ -98,29 +100,22 @@ async fn pong(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
#[min_args(1)]
|
||||
async fn console(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
|
||||
// let input = msg.content.strip_prefix(";console ").to_owned();
|
||||
|
||||
// if input == Option::None {
|
||||
// msg.reply(ctx, "Not enough Parameters").await?;
|
||||
// return Ok(());
|
||||
// }
|
||||
|
||||
let data = ctx.data.read().await;
|
||||
|
||||
let sock = data.get::<TcpSock>().unwrap();
|
||||
// let conf = data.get::<Config>().unwrap();
|
||||
let conf = data.get::<Config>().unwrap();
|
||||
|
||||
// if !check_role(ctx, msg, conf).await.unwrap_or_else(|e| false) {
|
||||
// // msg.channel_id.say(ctx, "You do not have permission to use this command").await?;
|
||||
// msg.channel_id.send_message(ctx, |m| {
|
||||
// m.content("test")
|
||||
// .embed(|e| e
|
||||
// .title("No Permissions")
|
||||
// .description("You do not have permission to use this command")
|
||||
// .color(Color::RED))
|
||||
// }).await?;
|
||||
// return Ok(());
|
||||
// }
|
||||
|
||||
if !check_role(ctx, msg, &conf.roles.cons).await.unwrap_or_else(|e| true) {
|
||||
msg.channel_id.send_message(ctx, |m| {
|
||||
m.content("")
|
||||
.embed(|e| e
|
||||
.title("No Permissions")
|
||||
.description("You do not have permission to use this command")
|
||||
.color(Color::RED))
|
||||
}).await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
msg.channel_id.send_message(ctx, |m| {
|
||||
m.content("")
|
||||
@@ -133,6 +128,41 @@ async fn console(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
#[num_args(1)]
|
||||
#[aliases("a")]
|
||||
#[description("Give youself permissions to build in the mindustry server")]
|
||||
#[example("a ErkDog")]
|
||||
async fn auth(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||
|
||||
let data = ctx.data.read().await;
|
||||
|
||||
let sock = data.get::<TcpSock>().unwrap();
|
||||
let conf = data.get::<Config>().unwrap();
|
||||
|
||||
|
||||
if !check_role(ctx, msg, &conf.roles.auth).await.unwrap_or_else(|e| true) {
|
||||
msg.channel_id.send_message(ctx, |m| {
|
||||
m.content("")
|
||||
.embed(|e| e
|
||||
.title("No Permissions")
|
||||
.description("You do not have permission to use this command")
|
||||
.color(Color::RED))
|
||||
}).await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
msg.channel_id.send_message(ctx, |m| {
|
||||
m.content("")
|
||||
.embed(|e| e
|
||||
.title("Console")
|
||||
.description(cons_rw(sock, &format!("auth add {}", args.message())))
|
||||
.color((255, 219, 221))
|
||||
)
|
||||
}).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[command]
|
||||
async fn git(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
msg.reply(ctx, "https://mintyserver.net/git/poslop/Mindustry-Server-Discord-Bot").await?;
|
||||
@@ -145,8 +175,27 @@ async fn discord(ctx: &Context, msg: &Message) -> CommandResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// async fn check_role(ctx: &Context, msg: &Message, conf: &Config) -> Result<bool, SerenityError> {
|
||||
// let id = RoleId::from(u64::from_str(&conf.roles.cons))?;
|
||||
// let check = msg.author.has_role(ctx, msg.guild_id.unwrap(), id).await?;
|
||||
// Ok(check)
|
||||
// }
|
||||
async fn check_role(ctx: &Context, msg: &Message, conf: &Vec<String>) -> Result<bool, SerenityError> {
|
||||
let mut invalid_roles = 0;
|
||||
for v_id in conf {
|
||||
let u_id = match u64::from_str(&v_id) {
|
||||
Ok(n) => n,
|
||||
Err(e) =>
|
||||
{
|
||||
invalid_roles += 1;
|
||||
continue
|
||||
},
|
||||
};
|
||||
let id = RoleId::from(u_id);
|
||||
let check = msg.author.has_role(ctx, msg.guild_id.unwrap(), id).await?;
|
||||
if check {
|
||||
return Ok(check)
|
||||
}
|
||||
}
|
||||
|
||||
if invalid_roles == conf.len() {
|
||||
return Ok(true)
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
@@ -35,8 +35,8 @@ pub struct Config {
|
||||
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
pub struct Roles {
|
||||
pub auth: String,
|
||||
pub cons: String
|
||||
pub auth: Vec<String>,
|
||||
pub cons: Vec<String>
|
||||
}
|
||||
|
||||
impl TypeMapKey for Config {
|
||||
@@ -100,8 +100,8 @@ let mut toml_file = OpenOptions::new()
|
||||
port: String::from("6859"),
|
||||
prefix: String::from(";"),
|
||||
roles: Roles {
|
||||
auth: String::from(""),
|
||||
cons: String::from("")
|
||||
auth: vec![String::from(""), String::from("")],
|
||||
cons: vec![String::from("")]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user