command descriptions

This commit is contained in:
2025-02-13 22:09:37 +01:00
parent 6cd8955252
commit 95b430440c
3 changed files with 21 additions and 120 deletions
+11 -1
View File
@@ -16,7 +16,11 @@ enum HelpOptions {
}
#[poise::command(slash_command, prefix_command, guild_only)]
#[poise::command(
slash_command,
prefix_command
)]
/// Shows helpful information on how to use the bk_week section of the bot.
pub async fn bk_week_help(
ctx: Context<'_>,
#[description = "Discord or Reddit help."] option: HelpOptions
@@ -44,6 +48,7 @@ pub async fn bk_week_help(
#[poise::command(slash_command, prefix_command, guild_only)]
/// Retrieves the data of a single post just for you. The data has to be within the database to work.
pub async fn bk_week_get(
ctx: Context<'_>,
#[description = "The post URL"] url: String
@@ -163,6 +168,7 @@ async fn send_data_corrupted_message(ctx: Context<'_>, url: &str) {
#[poise::command(slash_command, prefix_command, guild_only)]
/// Fetches a post from Reddit and adds it to the database.
pub async fn bk_week_add(
ctx: Context<'_>,
#[description = "The post URL"] url: String,
@@ -215,6 +221,7 @@ async fn send_updated_msg(ctx: Context<'_>, url: &str) {
#[poise::command(slash_command, prefix_command, guild_only)]
/// Removes a post from the database. It will show who last removed it.
pub async fn bk_week_remove(
ctx: Context<'_>,
#[description = "The post URL"] url: String
@@ -242,6 +249,7 @@ pub async fn bk_week_remove(
#[poise::command(slash_command, prefix_command, guild_only)]
/// Approves a post in the database. Approving posts tells the bot that it's original.
pub async fn bk_week_approve(
ctx: Context<'_>,
#[description = "The post URL"] url: String
@@ -283,6 +291,7 @@ async fn approve_cmd(ctx: Context<'_>, url: &str, reddit_data: &Value, approve:
#[poise::command(slash_command, prefix_command, guild_only)]
/// Opposite effects of `/bk_week_approve`.
pub async fn bk_week_disapprove(
ctx: Context<'_>,
#[description = "The post URL"] url: String
@@ -298,6 +307,7 @@ pub async fn bk_week_disapprove(
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR", guild_only)]
/// Sets the channel where the bot will dump all log info. It's reccommended to only run this once.
pub async fn bk_week_bind(
ctx: Context<'_>
) -> Result<(), Error>
+9 -117
View File
@@ -5,13 +5,14 @@ use crate::websocket::send_cmd_json;
use crate::{data, Context, Error};
use crate::messages::{send_embed, send_msg, edit_msg, EmbedOptions};
use poise::serenity_prelude::{GetMessages, OnlineStatus, Timestamp, UserId};
use poise::serenity_prelude::{OnlineStatus, Timestamp, UserId};
use rand::{seq::IteratorRandom, Rng};
use regex::Regex;
use serde_json::json;
#[poise::command(slash_command, prefix_command)]
/// Check if you have connection to the bot.
pub async fn ping(
ctx: Context<'_>,
#[description = "The text to echo back."] text: Option<String>,
@@ -24,6 +25,7 @@ pub async fn ping(
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR")]
/// Stops the bot... if you're mighty enough!
pub async fn stop(
ctx: Context<'_>,
#[description = "Type \"i want to stop the bot now\" to confirm."] confirmation: Option<String>,
@@ -62,6 +64,7 @@ pub async fn stop(
prefix_command,
default_member_permissions = "ADMINISTRATOR"
)]
/// Creates an embed.
pub async fn embed(
ctx: Context<'_>,
#[description = "Title of embed."] title: Option<String>,
@@ -96,7 +99,8 @@ pub async fn embed(
}
#[poise::command(slash_command, prefix_command)]
#[poise::command(slash_command, prefix_command, rename = "8_ball")]
/// Magic 8-ball. Ask a question, get an answer.
pub async fn eight_ball(
ctx: Context<'_>,
#[description = "Question to ask."] question: String
@@ -117,80 +121,8 @@ pub async fn eight_ball(
}
#[poise::command(
slash_command,
prefix_command,
default_member_permissions = "ADMINISTRATOR"
)]
pub async fn write_json(
ctx: Context<'_>,
#[description = "Delete all messages sent by the bot in the selected channel."] remove_all: Option<bool>,
#[description = "Includes \"Use '/rule {rule}' to view rules individually\" preset message"] include_rule_command: Option<bool>,
#[description = "JSON (empty is preset file)"] json: Option<String>
) -> Result<(), Error>
{
let rm_all = remove_all.unwrap_or_else(|| false);
let include_cmd = include_rule_command.unwrap_or_else(|| false);
if rm_all {
let progress = send_msg(ctx, "Deleting all messages in channel...".to_string(), true, true).await;
let builder = GetMessages::new().limit(100);
let msgs = ctx.channel_id().messages(ctx.http(), builder).await?;
for msg in msgs {
if msg.author.id == ctx.framework().bot_id {
msg.delete(ctx.http()).await?;
}
}
edit_msg(ctx, progress.unwrap(), "Deleting all messages in channel... Done!".to_string()).await;
}
let json_str = json.clone().unwrap_or_else(||
std::fs::read_to_string("./data/write_json.json")
.expect("No JSON preset file exists.")
).to_string();
let json_json: serde_json::Value = serde_json::from_str(&json_str).expect("JSON was improperly formatted");
if !json_json.is_array() {
send_msg(ctx, "JSON is not an array of strings".to_string(), true, true).await;
return Ok(());
}
for i in json_json.as_array().unwrap() {
if !i.is_object() { continue; }
let title = i["title"].to_string();
let title_str = title[1..title.len() - 1].to_string();
let desc = i["desc"].to_string();
let desc_str = desc[1..desc.len() - 1].to_string();
let index_str = i["index"].to_string();
let title_format = if index_str.len() > 0
{ format!("{} - {}", index_str, title_str) }
else { title_str };
let embed = EmbedOptions {
title: Some(title_format),
desc: desc_str,
..Default::default()
};
send_embed(ctx, embed, false).await;
}
if include_cmd && json.is_none() {
send_msg(ctx, "Use /rules thank you".to_string(), false, false).await;
}
return Ok(());
}
#[poise::command(slash_command, prefix_command)]
/// Convert a long reddit URL to a short one. The bot ONLY uses shortURLs when asking for one.
pub async fn re_shorturl(
ctx: Context<'_>,
#[description = "A Reddit post URL"] url: String
@@ -204,7 +136,7 @@ pub async fn re_shorturl(
send_msg(ctx, format!("ShortURL: <{}>", short_url), true, true).await;
}
else {
println!("Post ID not found in the URL");
send_msg(ctx, "Couldn't convert to shortURL: Invalid URL".to_string(), true, true).await;
}
return Ok(());
@@ -212,6 +144,7 @@ pub async fn re_shorturl(
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR", guild_only)]
/// Add your server to my database so I can sell it! (/s), I only store some minimal data the bot needs.
pub async fn add_server(
ctx: Context<'_>
) -> Result<(), Error>
@@ -227,44 +160,3 @@ pub async fn add_server(
return Ok(());
}
/* async fn autocomplete_rule_list(_: Context<'_>, _partial: &str) -> Vec<String> {
let json_str = std::fs::read_to_string("./data/write_json.json")
.expect("No JSON preset file exists.");
let json_json: serde_json::Value = serde_json::from_str(&json_str).expect("JSON was improperly formatted");
if json_json.is_array() {
let mut titles: Vec<String> = vec![];
for i in json_json.as_array().unwrap() {
let title = i["title"].to_string();
let title_str = title[1..title.len() - 1].to_string();
let index_str = i["index"].to_string();
let title_format = if index_str.len() > 0
{ format!("{} - {}", index_str, title_str) }
else { title_str };
titles.push(title_format);
}
return titles;
}
else {
return vec!["JSON data not found".to_string()];
}
}
#[poise::command(slash_command, prefix_command)]
pub async fn rule(
_ctx: Context<'_>,
#[description = "The name of the rule to display"]
#[autocomplete = "autocomplete_rule_list"]
_rule: Vec<String>
) -> Result<(), Error>
{
return Ok(());
}
*/
+1 -2
View File
@@ -22,7 +22,7 @@ use tokio::runtime::Runtime;
use serde_json;
// TODO: command descriptions
// TODO: update bk_week help files
// TODO: bot command permissions
// TODO: bk_mod verification system
@@ -144,7 +144,6 @@ async fn gen_bot(data: Data) -> Client {
cmds::embed(),
cmds::stop(),
cmds::eight_ball(),
cmds::write_json(),
cmds::re_shorturl(),
cmds::add_server(),
//cmds::rule(),