Move to poise, add slash commands

This commit is contained in:
Elnu 2022-11-14 23:05:17 -08:00
parent d397bb7117
commit 9e9eb48025
8 changed files with 385 additions and 404 deletions

View file

@ -1,38 +1,26 @@
use serenity::framework::standard::{macros::command, Args, CommandResult};
use serenity::model::prelude::*;
use serenity::prelude::*;
#![allow(non_snake_case)]
use crate::Context;
use crate::Error;
use poise::command;
use serde_json::json;
use std::env;
use crate::utils::*;
use crate::ShardManagerContainer;
#[command]
#[owners_only]
async fn sleep(ctx: &Context, msg: &Message) -> CommandResult {
let data = ctx.data.read().await;
if let Some(manager) = data.get::<ShardManagerContainer>() {
msg.reply(ctx, "Good night!").await?;
manager.lock().await.shutdown_all().await;
} else {
msg.reply(ctx, "There was a problem getting the shard manager")
.await?;
return Ok(());
}
#[command(prefix_command, hide_in_help, owners_only)]
pub async fn sleep(ctx: Context<'_>) -> Result<(), crate::Error> {
ctx.say("Good night!").await?;
ctx.framework().shard_manager.lock().await.shutdown_all().await;
Ok(())
}
#[command]
#[owners_only]
#[allow(non_snake_case)]
async fn setSubmissionChannel(ctx: &Context, msg: &Message) -> CommandResult {
#[command(prefix_command, hide_in_help, owners_only)]
pub async fn setsubmissionchannel(ctx: Context<'_>) -> Result<(), Error> {
let mut guild_data = get_guild_data();
let guild = msg.guild_id.unwrap().as_u64().to_string();
let channel = msg.channel_id.as_u64().to_string();
let guild = ctx.guild_id().unwrap().as_u64().to_string();
let channel = ctx.channel_id().as_u64().to_string();
if guild_data.contains_key(&guild) {
let mut current_guild_data = guild_data[&guild].as_object().unwrap().clone();
if current_guild_data.contains_key("submissionChannel") {
@ -45,23 +33,21 @@ async fn setSubmissionChannel(ctx: &Context, msg: &Message) -> CommandResult {
guild_data.insert(guild, json!({ "submissionChannel": channel }));
}
set_guild_data(guild_data);
msg.reply(
&ctx.http,
ctx.say(
format!(
"Submission channel for **{}** set to <#{}>.",
msg.guild(&ctx).unwrap().name,
msg.channel_id
ctx.guild().unwrap().name,
ctx.channel_id()
),
)
.await?;
Ok(())
}
#[command]
#[owners_only]
#[allow(non_snake_case)]
async fn setSuggestionChannel(ctx: &Context, msg: &Message) -> CommandResult {
let channel = msg.channel_id.as_u64().to_string();
#[command(prefix_command, hide_in_help, owners_only)]
pub async fn setsuggestionchannel(ctx: Context<'_>) -> Result<(), Error> {
let channel = ctx.channel_id().as_u64().to_string();
let message = format!("Submission channel set to <#{}>.", channel);
let mut guild_data = get_guild_data();
if guild_data.contains_key("submissionChannel") {
guild_data["suggestionChannel"] = channel.into();
@ -69,29 +55,19 @@ async fn setSuggestionChannel(ctx: &Context, msg: &Message) -> CommandResult {
guild_data.insert(String::from("suggestionChannel"), channel.into());
}
set_guild_data(guild_data);
msg.reply(
&ctx.http,
format!("Submission channel set to <#{}>.", msg.channel_id),
)
.await?;
ctx.say(message).await?;
Ok(())
}
#[command]
#[owners_only]
#[command(prefix_command, hide_in_help, owners_only)]
#[allow(non_snake_case)]
async fn setAnnouncementRole(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let role;
match args.single::<u64>() {
Ok(id) => role = id.to_string(),
Err(_) => {
msg.reply(&ctx.http, "Please provide an announcement role ID.")
.await?;
return Ok(());
}
}
pub async fn setannouncementrole(
ctx: Context<'_>,
#[description = "Announcement role ID"]
role: u64,
) -> Result<(), Error> {
let mut guild_data = get_guild_data();
let guild = msg.guild_id.unwrap().as_u64().to_string();
let guild = ctx.guild_id().unwrap().as_u64().to_string();
if guild_data.contains_key(&guild) {
let mut current_guild_data = guild_data[&guild].as_object().unwrap().clone();
if current_guild_data.contains_key("announcementRole") {
@ -104,20 +80,21 @@ async fn setAnnouncementRole(ctx: &Context, msg: &Message, mut args: Args) -> Co
guild_data.insert(guild, json!({ "announcementRole": role }));
}
set_guild_data(guild_data);
msg.reply(&ctx.http, "Announcement role set.").await?;
ctx.say("Announcement role set.").await?;
Ok(())
}
#[command]
#[owners_only]
async fn announce(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
send(ctx, msg, args.rest(), true, false).await
#[command(prefix_command, hide_in_help, owners_only)]
pub async fn announce(
ctx: Context<'_>,
#[description = "Announcement text"]
announcement: String,
) -> Result<(), Error> {
send(ctx, &announcement, true, false).await
}
#[command]
#[owners_only]
#[allow(non_snake_case)]
async fn announceChallenge(ctx: &Context, msg: &Message) -> CommandResult {
#[command(prefix_command, hide_in_help, owners_only)]
pub async fn announcechallenge(ctx: Context<'_>) -> Result<(), Error> {
let challenge_number = get_challenge_number();
let message = format!("Welcome to the **{n}{th}** weekly **Tegaki Tuesday** (手書きの火曜日) handwriting challenge! :pen_fountain: The prompt is available in both Japanese and English on the website at <https://tegakituesday.com/{n}>.
@ -131,15 +108,14 @@ You can make submissions in both languages, but please submit in your target lan
},
p = env::var("PREFIX").unwrap()
);
send(ctx, msg, &message, true, false).await
}
#[command]
#[owners_only]
#[allow(non_snake_case)]
async fn rebuildSite(ctx: &Context, msg: &Message) -> CommandResult {
rebuild_site();
msg.reply(&ctx.http, "Started site rebuild process!")
.await?;
send(ctx, &message, true, false).await?;
ctx.say("Announced!").await?;
Ok(())
}
#[command(prefix_command, hide_in_help, owners_only)]
pub async fn rebuildsite(ctx: Context<'_>) -> Result<(), Error> {
rebuild_site();
ctx.say("Started site rebuild process!").await?;
Ok(())
}