spam reduction & config command
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
<!-- - [x] Security that only allows bk mods to run these commands. -->
|
||||
<!-- - [x] Some kind of voting system. -->
|
||||
- [ ] `/bk_week_top [category] [amount]` to get the top N posts in a category (e.g upvotes)
|
||||
<!-- - [x] ~~`/bk_cfg_sr [subreddit]` to change the target subreddit(s)~~ -->
|
||||
- [ ] Allow updating the data autonomously and via manual commands.
|
||||
<!-- - [ ] 10-minute schedule for updating Discord channel (IMPOSSIBLE / REALLY FUCKING HARD) -->
|
||||
<!-- - [x] ~~Manually add posts~~ -->
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
/bk_week_top - get the top posts in a category
|
||||
@@ -643,3 +643,26 @@ pub async fn bk_week_vote(
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#[poise::command(slash_command, prefix_command, default_member_permissions = "ADMINISTRATOR")]
|
||||
/// Changes the subreddit(s) the bot patrols in.
|
||||
pub async fn bk_cfg_sr(ctx: Context<'_>, sr: String) -> Result<(), Error> {
|
||||
if !cmds::is_creator(ctx) {
|
||||
send_msg(ctx, "Failed to update subreddits: Invalid permissions.".to_string(), true, true).await;
|
||||
}
|
||||
|
||||
let r = send_cmd_json("change_sr", Some(json!([sr]))).await;
|
||||
|
||||
if r.is_some() {
|
||||
if r.unwrap()["value"].as_bool().unwrap() {
|
||||
send_msg(ctx, "Successfully updated subreddits!".to_string(), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
send_msg(ctx, "Failed to update subreddits: Failed-type response from Python.".to_string(), true, true).await;
|
||||
return Ok(());
|
||||
}
|
||||
+6
-1
@@ -33,7 +33,7 @@ pub async fn stop(
|
||||
let should_stop = ctx.data().args.dev
|
||||
|| confirmation.unwrap_or_else(|| "".to_string()).to_lowercase() == "i want to stop the bot now";
|
||||
|
||||
let is_creator = ctx.author().id == UserId::new(ctx.data().byte_dice_id);
|
||||
let is_creator = is_creator(ctx);
|
||||
|
||||
if should_stop && is_creator {
|
||||
let msg = send_msg(ctx, "Saving data...".to_string(), true, true).await.unwrap();
|
||||
@@ -58,6 +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(
|
||||
slash_command,
|
||||
prefix_command,
|
||||
|
||||
+6
-2
@@ -189,14 +189,18 @@ async fn gen_bot(data: Data, args: Args) -> Client {
|
||||
cmds::re_shorturl(),
|
||||
cmds::add_server(),
|
||||
//cmds::rule(),
|
||||
// bk_week
|
||||
bk_week_cmds::bk_week_help(),
|
||||
bk_week_cmds::bk_week_get(),
|
||||
bk_week_cmds::bk_week_add(),
|
||||
bk_week_cmds::bk_week_remove(),
|
||||
bk_week_cmds::bk_week_approve(),
|
||||
bk_week_cmds::bk_admin_bind(),
|
||||
bk_week_cmds::bk_week_update(),
|
||||
bk_week_cmds::bk_week_vote()
|
||||
bk_week_cmds::bk_week_vote(),
|
||||
// bk_admin
|
||||
bk_week_cmds::bk_admin_bind(),
|
||||
// bk_cfg
|
||||
bk_week_cmds::bk_cfg_sr()
|
||||
],
|
||||
event_handler: events::event_handler,
|
||||
..Default::default()
|
||||
|
||||
@@ -47,3 +47,7 @@ class Bot:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
async def change_sr(self, new_sr) -> bool:
|
||||
self.sr = await self.r.subreddit(new_sr)
|
||||
return True
|
||||
@@ -35,7 +35,8 @@ async def websocket_client(bot: botPy.Bot):
|
||||
|
||||
while True:
|
||||
response = await ws.recv()
|
||||
py_print(f"Received from Rust: {response}")
|
||||
if not response.startswith("json:"):
|
||||
py_print(f"Received from Rust: {response}")
|
||||
await parse_json(response, bot)
|
||||
|
||||
|
||||
@@ -44,6 +45,9 @@ async def parse_json(response: str, bot: botPy.Bot):
|
||||
json_str = response[5:]
|
||||
try:
|
||||
json_response = json.loads(json_str)
|
||||
if json_response["value"] not in ["respond_mentions"] or bot.args["dev"]:
|
||||
py_print(f"Received from Rust: {response}")
|
||||
|
||||
result = await json_to_func(json_response, bot)
|
||||
await ws_global.ping()
|
||||
await send_message(f"json:{json.dumps(result)}")
|
||||
@@ -72,12 +76,13 @@ async def json_to_func(v: dict, bot: botPy.Bot) -> dict:
|
||||
match v["value"]:
|
||||
case "update_data_file": r = data .write_data (bot)
|
||||
case "add_new_posts": r = await posts.add_new_posts (bot)
|
||||
case "respond_mentions": r = await cmds .respond_to_mention(bot)
|
||||
case "add_post_url": r = await posts.add_post_url (bot, *v["args"])
|
||||
case "remove_post_url": r = data .remove_post (bot, *v["args"])
|
||||
case "set_approve_post": r = data .set_approve_post (bot, *v["args"])
|
||||
case "set_vote_post": r = data .set_vote_post (bot, *v["args"])
|
||||
case "respond_mentions": r = await cmds .respond_to_mention(bot)
|
||||
case "stop_praw": r = await bot .stop()
|
||||
case "change_sr": r = await bot .change_sr (*v["args"])
|
||||
case "stop_praw": r = await bot .stop ()
|
||||
case _: value_supported = False
|
||||
|
||||
if not value_supported:
|
||||
|
||||
+3
-1
@@ -65,7 +65,9 @@ pub async fn send_cmd_json(func_name: &str, func_args: Option<Value>) -> Option<
|
||||
}
|
||||
|
||||
let r = receive_response().await;
|
||||
rs_println!("Received from Python: [RESPONSE] {:?}", r);
|
||||
if !["respond_mentions"].contains(&func_name) || <Args as clap::Parser>::parse().dev {
|
||||
rs_println!("Received from Python: [RESPONSE] {:?}", r);
|
||||
}
|
||||
|
||||
if r.is_none() {
|
||||
rs_println!("--- Response from Python is None!");
|
||||
|
||||
Reference in New Issue
Block a user