updated command metadata

This commit is contained in:
2025-03-01 00:24:25 +01:00
parent 1e6ad4e22f
commit 1466448fd3
4 changed files with 83 additions and 36 deletions
+1
View File
@@ -38,6 +38,7 @@ You can install Python modules by running `$ pip install {module}` or `$ python
| `ASSISTANT_R_TOKEN` | The token for the Reddit bot/account. | | `ASSISTANT_R_TOKEN` | The token for the Reddit bot/account. |
| `ASSISTANT_R_NAME` | The username of the Reddit bot/account. | | `ASSISTANT_R_NAME` | The username of the Reddit bot/account. |
| `ASSISTANT_R_PASS` | The password for the Reddit bot/account. | | `ASSISTANT_R_PASS` | The password for the Reddit bot/account. |
| `ASSISTANT_OWNERS` | A list of user ids that "own" the bot. Separate each owner with a comma and NO spaces. |
### How to run: ### How to run:
* Download the code (and extract if needed). * Download the code (and extract if needed).
+58 -18
View File
@@ -71,7 +71,10 @@ pub async fn bk_week_help(
#[poise::command(slash_command, prefix_command)] #[poise::command(
slash_command,
prefix_command
)]
/// Retrieves the data of a single post just for you. The data has to be within the database to work. /// 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( pub async fn bk_week_get(
ctx: Context<'_>, ctx: Context<'_>,
@@ -169,7 +172,10 @@ async fn send_data_corrupted_message(ctx: Context<'_>, url: &str) {
#[poise::command(slash_command, prefix_command)] #[poise::command(
slash_command,
prefix_command
)]
/// Fetches a post from Reddit and adds it to the database. /// Fetches a post from Reddit and adds it to the database.
pub async fn bk_week_add( pub async fn bk_week_add(
ctx: Context<'_>, ctx: Context<'_>,
@@ -237,7 +243,10 @@ async fn send_updated_msg(ctx: Context<'_>, url: &str) {
#[poise::command(slash_command, prefix_command)] #[poise::command(
slash_command,
prefix_command
)]
/// Removes a post from the database. It will show who last removed it. /// Removes a post from the database. It will show who last removed it.
pub async fn bk_week_remove( pub async fn bk_week_remove(
ctx: Context<'_>, ctx: Context<'_>,
@@ -271,7 +280,10 @@ pub async fn bk_week_remove(
#[poise::command(slash_command, prefix_command)] #[poise::command(
slash_command,
prefix_command
)]
/// Approves a post in the database. Approving posts tells the bot that it's original. /// Approves a post in the database. Approving posts tells the bot that it's original.
pub async fn bk_week_approve( pub async fn bk_week_approve(
ctx: Context<'_>, ctx: Context<'_>,
@@ -321,7 +333,12 @@ async fn approve_cmd(ctx: Context<'_>, url: &str, reddit_data: &Value, approve:
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR", guild_only)] #[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 recommended to only run this once. /// Sets the channel where the bot will dump all log info. It's recommended to only run this once.
pub async fn bk_admin_bind( pub async fn bk_admin_bind(
ctx: Context<'_> ctx: Context<'_>
@@ -348,12 +365,21 @@ async fn send_server_not_in_data_msg(ctx: Context<'_>) {
#[poise::command(slash_command, prefix_command, guild_only)] #[poise::command(
slash_command,
prefix_command,
guild_only,
guild_cooldown = 120
)]
/// Updates all logs /// Updates all logs
pub async fn bk_week_update( pub async fn bk_week_update(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Only adds new posts, leaves everything else unchanged."] only_add: Option<bool>, #[description = "Only adds new posts, leaves everything else unchanged."]
#[description = "The max age of a post (in days). Any post older than this will be removed. (0 is infinite.)"] max_age: Option<u16> only_add: Option<bool>,
#[description = "The max age of a post (in days). Any post older than this will be removed. (0 is infinite.)"]
#[min = 0]
#[max = 65535]
max_age: Option<u16>
) -> Result<(), Error> ) -> Result<(), Error>
{ {
let http = ctx.http(); let http = ctx.http();
@@ -630,7 +656,10 @@ async fn remove_dupes(http: &Http, c_id: ChannelId, msgs_json: &Value) {
} }
#[poise::command(slash_command, prefix_command)] #[poise::command(
slash_command,
prefix_command
)]
/// Adds/removes a vote from a post. These votes are not tied to Reddit upvotes. /// Adds/removes a vote from a post. These votes are not tied to Reddit upvotes.
pub async fn bk_week_vote( pub async fn bk_week_vote(
ctx: Context<'_>, ctx: Context<'_>,
@@ -690,12 +719,19 @@ pub async fn bk_week_vote(
#[poise::command(slash_command, prefix_command)] #[poise::command(
slash_command,
prefix_command
)]
/// Gets the top N (up to 10) posts within a certain category, such as upvotes. (Sorted descending.) /// Gets the top N (up to 10) posts within a certain category, such as upvotes. (Sorted descending.)
pub async fn bk_week_top( pub async fn bk_week_top(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "The sorting criteria, such as upvotes."] category: TopCategory, #[description = "The sorting criteria, such as upvotes."]
#[description = "The amount of posts to show (max 10)."] amount: Option<u8> category: TopCategory,
#[description = "The amount of posts to show (max 10)."]
#[min = 1]
#[max = 10]
amount: Option<u8>
) -> Result<(), Error> ) -> Result<(), Error>
{ {
let mut all: HashMap<&str, i32> = HashMap::new(); let mut all: HashMap<&str, i32> = HashMap::new();
@@ -751,13 +787,17 @@ fn smallest_n<'a>(map: &'a HashMap<&'a str, i32>, n: usize) -> Vec<(&'a str, i32
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR")] #[poise::command(
slash_command,
prefix_command,
owners_only
)]
/// Changes the subreddit(s) the bot patrols in. /// Changes the subreddit(s) the bot patrols in.
pub async fn bk_cfg_sr(ctx: Context<'_>, sr: String) -> Result<(), Error> { pub async fn bk_cfg_sr(
if !cmds::is_creator(ctx) { ctx: Context<'_>,
send_msg(ctx, "Failed to update subreddits: Invalid permissions.".to_string(), true, true).await; sr: String
} ) -> Result<(), Error>
{
let r = send_cmd_json("change_sr", Some(json!([sr]))).await; let r = send_cmd_json("change_sr", Some(json!([sr]))).await;
if r.is_some() { if r.is_some() {
+13 -16
View File
@@ -5,7 +5,7 @@ use crate::websocket::send_cmd_json;
use crate::{data, Context, Error}; use crate::{data, Context, Error};
use crate::messages::{edit_reply, send_embed, send_msg, Author, EmbedOptions, MANDATORY_MSG}; use crate::messages::{edit_reply, send_embed, send_msg, Author, EmbedOptions, MANDATORY_MSG};
use poise::serenity_prelude::{OnlineStatus, Timestamp, UserId}; use poise::serenity_prelude::{OnlineStatus, Timestamp};
use rand::{seq::IteratorRandom, Rng}; use rand::{seq::IteratorRandom, Rng};
use regex::Regex; use regex::Regex;
@@ -23,7 +23,12 @@ pub async fn ping(
} }
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR")] #[poise::command(
slash_command,
prefix_command,
default_member_permissions = "ADMINISTRATOR",
owners_only
)]
/// Stops the bot... if you're mighty enough! /// Stops the bot... if you're mighty enough!
pub async fn stop( pub async fn stop(
ctx: Context<'_>, ctx: Context<'_>,
@@ -33,9 +38,7 @@ pub async fn stop(
let should_stop = ctx.data().args.dev let should_stop = ctx.data().args.dev
|| confirmation.unwrap_or_else(|| "".to_string()).to_lowercase() == "i want to stop the bot now"; || confirmation.unwrap_or_else(|| "".to_string()).to_lowercase() == "i want to stop the bot now";
let is_creator = is_creator(ctx); if should_stop {
if should_stop && is_creator {
let msg = send_msg(ctx, "Saving data...".to_string(), true, true).await.unwrap(); let msg = send_msg(ctx, "Saving data...".to_string(), true, true).await.unwrap();
data::write_dc_data(ctx.data()).await; data::write_dc_data(ctx.data()).await;
data::write_re_data().await; data::write_re_data().await;
@@ -47,10 +50,7 @@ pub async fn stop(
process::exit(0); process::exit(0);
} }
else if !is_creator { else {
send_msg(ctx, "Failed to shut down: Invalid permissions.".to_string(), true, true).await;
}
else if !should_stop {
send_msg(ctx, "Failed to shut down: Invalid confirmation.".to_string(), true, true).await; send_msg(ctx, "Failed to shut down: Invalid confirmation.".to_string(), true, true).await;
} }
@@ -58,15 +58,11 @@ pub async fn stop(
} }
pub fn is_creator(ctx: Context<'_>) -> bool {
return ctx.author().id == UserId::new(ctx.data().byte_dice_id);
}
#[poise::command( #[poise::command(
slash_command, slash_command,
prefix_command, prefix_command,
default_member_permissions = "ADMINISTRATOR" default_member_permissions = "ADMINISTRATOR",
owners_only
)] )]
/// Creates an embed. /// Creates an embed.
pub async fn embed( pub async fn embed(
@@ -113,7 +109,8 @@ pub async fn embed(
#[poise::command( #[poise::command(
slash_command, slash_command,
prefix_command, prefix_command,
default_member_permissions = "ADMINISTRATOR" default_member_permissions = "ADMINISTRATOR",
owners_only
)] )]
/// Sends a message. /// Sends a message.
pub async fn send( pub async fn send(
+11 -2
View File
@@ -10,6 +10,7 @@ mod macros;
mod websocket; mod websocket;
mod data; mod data;
use std::collections::HashSet;
use std::future::Future; use std::future::Future;
use std::pin::Pin; use std::pin::Pin;
use std::process; use std::process;
@@ -18,6 +19,7 @@ use std::time::Duration;
use std::vec; use std::vec;
use clap::Parser; use clap::Parser;
use poise::serenity_prelude::UserId;
use poise::serenity_prelude as serenity; use poise::serenity_prelude as serenity;
use poise::serenity_prelude::Client; use poise::serenity_prelude::Client;
use serde::Serialize; use serde::Serialize;
@@ -60,7 +62,6 @@ type Context<'a> = poise::Context<'a, Data, Error>;
struct Data { struct Data {
ball_prompts: [Vec<String>; 2], ball_prompts: [Vec<String>; 2],
byte_dice_id: u64,
reddit_data: Mutex<Option<Value>>, reddit_data: Mutex<Option<Value>>,
discord_data: Mutex<Option<Value>>, discord_data: Mutex<Option<Value>>,
bk_mods_json: Value, bk_mods_json: Value,
@@ -148,7 +149,6 @@ async fn gen_data(args: Args) -> Data {
let data = Data { let data = Data {
ball_prompts: [ball_classic, ball_quirk], ball_prompts: [ball_classic, ball_quirk],
bk_mods_json: bk_mods, bk_mods_json: bk_mods,
byte_dice_id: 697149665166229614,
reddit_data: None.into(), reddit_data: None.into(),
discord_data: None.into(), discord_data: None.into(),
args: args.clone() args: args.clone()
@@ -177,9 +177,18 @@ async fn gen_bot(data: Data, args: Args) -> Client {
let token_end_len = token[peek_len..].len(); let token_end_len = token[peek_len..].len();
rs_println!("Token: {}{}", token_peek, "*".repeat(token_end_len)); rs_println!("Token: {}{}", token_peek, "*".repeat(token_end_len));
let own_env = std::env::var("ASSISTANT_OWNERS").expect("Missing ASSISTANT_OWNERS env var!");
let own_vec_str: Vec<String> = own_env.split(",").map(String::from).collect();
let own_vec_u64: Vec<u64> = own_vec_str
.iter()
.filter_map(|s| Some(s.parse::<u64>().expect("Failed to parse ASSISTANT_OWNERS. Invalid syntax.")))
.collect();
let own: HashSet<UserId> = own_vec_u64.into_iter().map(UserId::from).collect();
let framework = poise::Framework::builder() let framework = poise::Framework::builder()
.options(poise::FrameworkOptions { .options(poise::FrameworkOptions {
owners: own,
commands: vec![ commands: vec![
cmds::ping(), cmds::ping(),
cmds::embed(), cmds::embed(),