moved database-related commands into subcommands & added wwrps database entry

This commit is contained in:
2026-02-27 13:00:40 +01:00
parent b3a6a7eb25
commit 650cb98a3e
8 changed files with 83 additions and 26 deletions
+2 -1
View File
@@ -2,7 +2,8 @@
"servers": {
"SERVER ID": {
"re_posts_channel": 0,
"re_disabled": false
"re_disabled": false,
"wwrps_channel": 0
}
}
}
+20
View File
@@ -20,6 +20,7 @@ static PRESET_PATH_CFG: &str = "./data/defaults/cfg_default.toml";
static DATA_PATH_LANG: &str = "./data/lang/";
pub static DC_POSTS_CHANNEL_KEY: &str = "re_posts_channel";
pub static DC_WWRPS_CHANNEL_KEY: &str = "wwrps_channel";
pub async fn read_dc_data(data: &Data, wipe: bool) {
@@ -181,6 +182,25 @@ pub async fn dc_bind_bk(data: &Data, server_id: u64, channel_id: u64) -> Result<
}
pub async fn bind_wwrps(data: &Data, server_id: u64, channel_id: u64) -> Result<(), ()> {
let mut dc_data_lock = data.discord_data.lock().await;
let dc_data = dc_data_lock.as_mut().unwrap();
if dc_data.get("servers").is_none() { return Err(()); }
let servers = dc_data["servers"].as_object_mut().unwrap();
if !servers.contains_key(&server_id.to_string())
{ return Err(()); }
let server = servers[&server_id.to_string()].as_object_mut().unwrap();
server.insert(DC_WWRPS_CHANNEL_KEY.to_string(), channel_id.into());
return Ok(());
}
pub async fn dc_contains_server(data: &Data, server_id: u64) -> bool {
let dc_data_lock = data.discord_data.lock().await;
let dc_data = dc_data_lock.as_ref().unwrap();
@@ -1,16 +1,6 @@
use crate::{data::dc_add_server, lang, messages::send_msg, Context, Error};
#[poise::command(
slash_command,
prefix_command,
rename = "add_server",
category = "db",
default_member_permissions = "ADMINISTRATOR",
guild_only,
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
)]
/// Add your server to my database so I can sell it! (/s), I only store some minimal data the bot needs.
pub async fn cmd(
ctx: Context<'_>
) -> Result<(), Error>
+35
View File
@@ -0,0 +1,35 @@
use crate::{Context, Error, db_cmds::{add_server, reddit_channel, wwrps_channel}};
#[derive(poise::ChoiceParameter, PartialEq)]
pub enum Subcommands {
AddServer,
RedditChannel,
WWRPSChannel
}
#[poise::command(
slash_command,
prefix_command,
category = "db",
rename = "database",
owners_only,
default_member_permissions = "ADMINISTRATOR",
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
)]
/// Various debug utilities
pub async fn cmd(
ctx: Context<'_>,
#[description = "Subcommand"] subcommand: Subcommands,
) -> Result<(), Error>
{
match subcommand {
Subcommands::AddServer => add_server::cmd(ctx).await?,
Subcommands::RedditChannel => reddit_channel::cmd(ctx).await?,
Subcommands::WWRPSChannel => wwrps_channel::cmd(ctx).await?,
//_ => return Ok(())
}
return Ok(());
}
@@ -1,15 +1,5 @@
use crate::{data::dc_bind_bk, lang, messages::send_msg, Context, Error};
#[poise::command(
slash_command,
prefix_command,
rename = "admin_re_bindchannel",
category = "db",
default_member_permissions = "ADMINISTRATOR",
guild_only,
required_bot_permissions = "SEND_MESSAGES | VIEW_CHANNEL"
)]
/// Sets the channel where the bot will dump all Reddit data upon using /re_updateDiscord.
pub async fn cmd(
ctx: Context<'_>
) -> Result<(), Error>
+18
View File
@@ -0,0 +1,18 @@
use crate::{Context, Error, data::bind_wwrps, lang, messages::send_msg};
pub async fn cmd(
ctx: Context<'_>
) -> Result<(), Error>
{
let c_id = ctx.channel_id().into();
let r = bind_wwrps(ctx.data(), ctx.guild_id().unwrap().into(), c_id).await;
if r.is_ok() {
send_msg(ctx, lang!("dc_msg_bound_channel", c_id), true, true).await;
}
else {
send_msg(ctx, lang!("dc_msg_data_server_404"), true, true).await;
}
return Ok(());
}
+2 -3
View File
@@ -6,7 +6,7 @@ use poise::serenity_prelude::Client;
use toml::Value;
use crate::data::get_toml_mutex;
use crate::{Args, Cmd, Data, cmds, data, debug_cmds, events, re_cmds, rs_println};
use crate::{Args, Cmd, Data, cmds, data, db_cmds, debug_cmds, events, re_cmds, rs_println};
pub async fn gen_data(args: Args, owners: Vec<u64>) -> Data {
@@ -100,8 +100,7 @@ async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
cmds::send::cmd(),
debug_cmds::main_cmd::cmd(),
// DATABASE
re_cmds::admin_bind::cmd(),
cmds::add_server::cmd(),
db_cmds::main_cmd::cmd()
];
let cfg = get_toml_mutex(&data.cfg).await.unwrap();
+6 -2
View File
@@ -3,7 +3,6 @@
#![allow(static_mut_refs)]
mod cmds {
pub mod add_server;
pub mod eight_ball;
pub mod embed;
pub mod help;
@@ -11,7 +10,6 @@ mod cmds {
}
mod re_cmds {
pub mod add;
pub mod admin_bind;
pub mod approve;
pub mod generic_fns;
pub mod get;
@@ -31,6 +29,12 @@ mod debug_cmds {
pub mod view_guilds;
pub mod whoami;
}
mod db_cmds {
pub mod add_server;
pub mod reddit_channel;
pub mod main_cmd;
pub mod wwrps_channel;
}
mod events;
mod messages;
mod python;