Prevent submissions outside of designated submission channels

late-submissions
Elnu 3 years ago
parent 15ab2de365
commit c3baa99068

@ -16,6 +16,8 @@ use std::process::Command;
use slug::slugify;
use crate::commands::owner::get_guild_data;
fn get_challenge_number() -> i32 {
let challenge_dir = format!("{}/content/challenges", env::var("HUGO").unwrap());
let paths = fs::read_dir(challenge_dir).unwrap();
@ -121,6 +123,17 @@ async fn challenge(ctx: &Context, msg: &Message) -> CommandResult {
async fn submit(ctx: &Context, msg: &Message) -> CommandResult {
// TODO: The code for this command needs to be refactored,
// there are large duplicated sections that need to be merged somehow.
let guild_data = get_guild_data();
let guild = msg.guild_id.unwrap().as_u64().to_string();
if !guild_data.contains_key(&guild) {
msg.reply(&ctx.http, "Submissions aren't enabled for this server yet.").await?;
return Ok(());
}
let submission_channel = &guild_data[&guild].as_object().unwrap()["submissionChannel"].as_str().unwrap();
if submission_channel != &msg.channel_id.as_u64().to_string() {
msg.reply(&ctx.http, format!("Sorry, submissions aren't permitted here. Please go to <#{}>. Thanks!", submission_channel)).await?;
return Ok(());
}
if msg.attachments.len() == 0 {
msg.reply(&ctx.http, "Please attach at least one image.")
.await?;

@ -16,7 +16,7 @@ use crate::ShardManagerContainer;
const GUILD_DATA_PATH: &str = "guilds.json";
fn get_guild_data() -> Map<String, Value> {
pub fn get_guild_data() -> Map<String, Value> {
let guild_data_json = match File::open(GUILD_DATA_PATH) {
Ok(mut file) => {
let mut json = String::new();

Loading…
Cancel
Save