late-submissions
Elnu 3 years ago
parent a1c3e7c047
commit 38318687dc

@ -118,7 +118,8 @@ fn rebuild_site() {
#[allow(non_snake_case)] #[allow(non_snake_case)]
async fn rebuildSite(ctx: &Context, msg: &Message) -> CommandResult { async fn rebuildSite(ctx: &Context, msg: &Message) -> CommandResult {
rebuild_site(); rebuild_site();
msg.reply(&ctx.http, "Started site rebuild process!").await?; msg.reply(&ctx.http, "Started site rebuild process!")
.await?;
Ok(()) Ok(())
} }
@ -133,7 +134,8 @@ async fn pullAndRebuildSite(ctx: &Context, msg: &Message) -> CommandResult {
.expect("Failed to git pull") .expect("Failed to git pull")
.wait()?; .wait()?;
rebuild_site(); rebuild_site();
msg.reply(&ctx.http, "Pulled and started site rebuild process!").await?; msg.reply(&ctx.http, "Pulled and started site rebuild process!")
.await?;
Ok(()) Ok(())
} }
@ -156,9 +158,14 @@ async fn submit(ctx: &Context, msg: &Message) -> CommandResult {
// there are large duplicated sections that need to be merged somehow. // there are large duplicated sections that need to be merged somehow.
let guild_data = get_guild_data(); let guild_data = get_guild_data();
let guild = msg.guild_id.unwrap().as_u64().to_string(); let guild = msg.guild_id.unwrap().as_u64().to_string();
if !guild_data.contains_key(&guild) || !&guild_data[&guild].as_object().unwrap().contains_key("submissionChannel") { if !guild_data.contains_key(&guild)
|| !&guild_data[&guild]
.as_object()
.unwrap()
.contains_key("submissionChannel")
{
msg.reply(&ctx.http, "Submissions aren't enabled for this server yet.") msg.reply(&ctx.http, "Submissions aren't enabled for this server yet.")
.await?; .await?;
return Ok(()); return Ok(());
} }
let current_guild_data = &guild_data[&guild].as_object().unwrap(); let current_guild_data = &guild_data[&guild].as_object().unwrap();

@ -5,14 +5,14 @@ use serenity::prelude::*;
use serde_json::json; use serde_json::json;
use serde_json::Map; use serde_json::Map;
use serde_json::Value; use serde_json::Value;
use std::env;
use std::fs::File; use std::fs::File;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::Read; use std::io::Read;
use std::io::Write; use std::io::Write;
use std::env;
use crate::ShardManagerContainer;
use crate::commands::challenge::get_challenge_number; use crate::commands::challenge::get_challenge_number;
use crate::ShardManagerContainer;
fn get_guild_data_path() -> String { fn get_guild_data_path() -> String {
env::var("GUILD_DATA").unwrap() env::var("GUILD_DATA").unwrap()
@ -93,7 +93,11 @@ async fn setSubmissionChannel(ctx: &Context, msg: &Message) -> CommandResult {
set_guild_data(guild_data); set_guild_data(guild_data);
msg.reply( msg.reply(
&ctx.http, &ctx.http,
format!("Submission channel for **{}** set to <#{}>.", msg.guild(&ctx).await.unwrap().name, msg.channel_id), format!(
"Submission channel for **{}** set to <#{}>.",
msg.guild(&ctx).await.unwrap().name,
msg.channel_id
),
) )
.await?; .await?;
Ok(()) Ok(())
@ -107,7 +111,8 @@ async fn setAnnouncementRole(ctx: &Context, msg: &Message, mut args: Args) -> Co
match args.single::<u64>() { match args.single::<u64>() {
Ok(id) => role = id.to_string(), Ok(id) => role = id.to_string(),
Err(_) => { Err(_) => {
msg.reply(&ctx.http, "Please provide an announcement role ID.").await?; msg.reply(&ctx.http, "Please provide an announcement role ID.")
.await?;
return Ok(()); return Ok(());
} }
} }
@ -137,27 +142,47 @@ async fn send(ctx: &Context, msg: &Message, message: &str, ping: bool, pin: bool
if !data.contains_key("submissionChannel") { if !data.contains_key("submissionChannel") {
continue; continue;
} }
let channel = ChannelId(data["submissionChannel"].as_str().unwrap().parse::<u64>().unwrap()); let channel = ChannelId(
data["submissionChannel"]
.as_str()
.unwrap()
.parse::<u64>()
.unwrap(),
);
let mut message_to_send = String::from(""); let mut message_to_send = String::from("");
if ping && data.contains_key("announcementRole") { if ping && data.contains_key("announcementRole") {
message_to_send.push_str(&format!("<@&{}> ", data["announcementRole"].as_str().unwrap())); message_to_send.push_str(&format!(
"<@&{}> ",
data["announcementRole"].as_str().unwrap()
));
} }
message_to_send.push_str(message); message_to_send.push_str(message);
let sent_message = channel.send_message(&ctx.http, |e| { let sent_message = channel
e.content(message_to_send); .send_message(&ctx.http, |e| {
e e.content(message_to_send);
}).await.unwrap(); e
})
.await
.unwrap();
if pin { if pin {
// No need to do anything on error, // No need to do anything on error,
// it just means we don't have pin permissions // it just means we don't have pin permissions
match sent_message.pin(&ctx.http).await { match sent_message.pin(&ctx.http).await {
Ok(_) => (), Ok(_) => (),
Err(_) => () Err(_) => (),
}; };
} }
announcements_count += 1; announcements_count += 1;
} }
msg.reply(&ctx.http, format!("Announced to {} server{}!", announcements_count, if announcements_count == 1 { "" } else { "s" })).await?; msg.reply(
&ctx.http,
format!(
"Announced to {} server{}!",
announcements_count,
if announcements_count == 1 { "" } else { "s" }
),
)
.await?;
Ok(()) Ok(())
} }
@ -185,4 +210,4 @@ You can make submissions in both languages, but please submit in your target lan
p = env::var("PREFIX").unwrap() p = env::var("PREFIX").unwrap()
); );
send(ctx, msg, &message, true, true).await send(ctx, msg, &message, true, true).await
} }

Loading…
Cancel
Save