figured out how to add buttons
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
- [ ] Reddit bot that scrapes images with tag "Original Art" and posts them in Discord server
|
- [ ] Reddit bot that scrapes images with tag "Original Art" and posts them in Discord server
|
||||||
- [ ] Allow updating the data autonomously and via manual commands.
|
- [ ] Allow updating the data autonomously and via manual commands.
|
||||||
- [ ] Automatically approve posts that don't get caught by reverse image search (ris)
|
- [ ] Automatically approve posts that don't get caught by reverse image search (ris)
|
||||||
|
- [ ] Make buttons do stuff
|
||||||
|
- [ ] Add buttons to removed post embed
|
||||||
<!-- - [ ] 10-minute schedule for updating Discord channel (IMPOSSIBLE / REALLY FUCKING HARD) -->
|
<!-- - [ ] 10-minute schedule for updating Discord channel (IMPOSSIBLE / REALLY FUCKING HARD) -->
|
||||||
|
|
||||||
### Medium priority:
|
### Medium priority:
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub async fn cmd(
|
|||||||
let r = dc_add_server(ctx.data(), ctx.guild_id().unwrap().into()).await;
|
let r = dc_add_server(ctx.data(), ctx.guild_id().unwrap().into()).await;
|
||||||
|
|
||||||
if r.is_ok() {
|
if r.is_ok() {
|
||||||
send_msg(ctx, lang!("dc_msg_added_to_data"), true, true).await;
|
send_msg(ctx, lang!("dc_msg_add_to_data"), true, true).await;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send_msg(ctx, lang!("dc_msg_corrupted_data"), true, true).await;
|
send_msg(ctx, lang!("dc_msg_corrupted_data"), true, true).await;
|
||||||
|
|||||||
+2
-1
@@ -39,7 +39,8 @@ pub async fn cmd(
|
|||||||
ephemeral: ephemeral.unwrap_or(false),
|
ephemeral: ephemeral.unwrap_or(false),
|
||||||
message,
|
message,
|
||||||
thumbnail,
|
thumbnail,
|
||||||
author: if author.unwrap_or(false) { Some(Author { name: ctx.author().name.clone(), url: "".to_string(), icon_url: ctx.author().avatar_url().unwrap() }) } else { None }
|
author: if author.unwrap_or(false) { Some(Author { name: ctx.author().name.clone(), url: "".to_string(), icon_url: ctx.author().avatar_url().unwrap() }) } else { None },
|
||||||
|
..Default::default()
|
||||||
},
|
},
|
||||||
reply_unwrap
|
reply_unwrap
|
||||||
).await;
|
).await;
|
||||||
|
|||||||
+1
-1
@@ -91,7 +91,7 @@ async fn make_cmd_vec(data: &Data) -> Vec<Cmd> {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// REDDIT
|
// REDDIT
|
||||||
if cfg["RESTART_enabled"].as_bool().unwrap() {
|
if cfg["reddit"]["RESTART_enabled"].as_bool().unwrap() {
|
||||||
cmds.extend([
|
cmds.extend([
|
||||||
re_cmds::add::cmd(),
|
re_cmds::add::cmd(),
|
||||||
re_cmds::approve::cmd(),
|
re_cmds::approve::cmd(),
|
||||||
|
|||||||
+1
-1
@@ -104,7 +104,7 @@ async fn main() {
|
|||||||
|
|
||||||
rs_println!("Fetching language file...");
|
rs_println!("Fetching language file...");
|
||||||
data::load_lang_data(args.clone().lang);
|
data::load_lang_data(args.clone().lang);
|
||||||
rs_println!("[IMPORTANT] The below message is a test message, it should be written in the language you've selected\n{}", lang!("log_lang_load_success"));
|
rs_println!("[IMPORTANT] The below message is a test message, it should be written in the language you've selected\nTest message: {}", lang!("log_lang_load_success"));
|
||||||
|
|
||||||
let own_env = std::env::var("ASSISTANT_OWNERS").unwrap_or("0".to_string());
|
let own_env = std::env::var("ASSISTANT_OWNERS").unwrap_or("0".to_string());
|
||||||
let own_vec_str: Vec<String> = own_env.split(",").map(String::from).collect();
|
let own_vec_str: Vec<String> = own_env.split(",").map(String::from).collect();
|
||||||
|
|||||||
+26
-5
@@ -4,7 +4,7 @@ use crate::{lang, Args, Context};
|
|||||||
|
|
||||||
use poise::serenity_prelude::json::Value;
|
use poise::serenity_prelude::json::Value;
|
||||||
use poise::{serenity_prelude::CreateMessage, CreateReply, ReplyHandle};
|
use poise::{serenity_prelude::CreateMessage, CreateReply, ReplyHandle};
|
||||||
use poise::serenity_prelude::{ChannelId, Color, CreateEmbed, CreateEmbedAuthor, EditMessage, Http, Message, Timestamp, UserId};
|
use poise::serenity_prelude::{ChannelId, Color, CreateActionRow, CreateButton, CreateEmbed, CreateEmbedAuthor, EditMessage, Http, Message, ReactionType, Timestamp, UserId};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +24,8 @@ pub struct EmbedOptions {
|
|||||||
pub ephemeral: bool,
|
pub ephemeral: bool,
|
||||||
pub message: Option<String>,
|
pub message: Option<String>,
|
||||||
pub author: Option<Author>,
|
pub author: Option<Author>,
|
||||||
pub thumbnail: Option<String>
|
pub thumbnail: Option<String>,
|
||||||
|
pub actionrows: Option<Vec<CreateActionRow>>
|
||||||
}
|
}
|
||||||
impl Default for EmbedOptions {
|
impl Default for EmbedOptions {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -37,7 +38,8 @@ impl Default for EmbedOptions {
|
|||||||
ephemeral: false,
|
ephemeral: false,
|
||||||
message: None,
|
message: None,
|
||||||
author: None,
|
author: None,
|
||||||
thumbnail: None
|
thumbnail: None,
|
||||||
|
actionrows: None
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,6 +106,7 @@ pub async fn send_embed(
|
|||||||
embeds: vec![embed],
|
embeds: vec![embed],
|
||||||
content: options.message,
|
content: options.message,
|
||||||
ephemeral: Some(options.ephemeral),
|
ephemeral: Some(options.ephemeral),
|
||||||
|
components: options.actionrows,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -111,7 +114,12 @@ pub async fn send_embed(
|
|||||||
return Some(msg.unwrap());
|
return Some(msg.unwrap());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
let r = CreateMessage::new().embeds(vec![embed]);
|
let mut r = CreateMessage::new().embeds(vec![embed]);
|
||||||
|
|
||||||
|
if let Some(actionrows) = options.actionrows {
|
||||||
|
r = r.components(actionrows);
|
||||||
|
}
|
||||||
|
|
||||||
let _ = ctx.channel_id().send_message(ctx.http(), r).await;
|
let _ = ctx.channel_id().send_message(ctx.http(), r).await;
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
@@ -126,7 +134,11 @@ pub async fn http_send_embed(
|
|||||||
{
|
{
|
||||||
let embed = embed_from_options(options.clone());
|
let embed = embed_from_options(options.clone());
|
||||||
|
|
||||||
let r = CreateMessage::new().embeds(vec![embed]);
|
let mut r = CreateMessage::new().embeds(vec![embed]);
|
||||||
|
|
||||||
|
if let Some(actionrows) = options.actionrows {
|
||||||
|
r = r.components(actionrows);
|
||||||
|
}
|
||||||
|
|
||||||
let msg = c_id.send_message(http, r).await;
|
let msg = c_id.send_message(http, r).await;
|
||||||
return msg.ok();
|
return msg.ok();
|
||||||
@@ -222,6 +234,14 @@ pub fn make_post_embed(post_data: &Value, url: &str, ephemeral: bool) -> EmbedOp
|
|||||||
);
|
);
|
||||||
let media_urls = post_data["post_data"]["media_urls"].as_array().unwrap();
|
let media_urls = post_data["post_data"]["media_urls"].as_array().unwrap();
|
||||||
|
|
||||||
|
let action_row = CreateActionRow::Buttons(vec![
|
||||||
|
CreateButton::new("upvote_btn") .label("Upvote") .emoji(ReactionType::Unicode("⬆️".to_string())),
|
||||||
|
CreateButton::new("unupvote_btn") .label("Un-upvote"),
|
||||||
|
CreateButton::new("approve_btn") .label("Approve") .emoji(ReactionType::Unicode("✅".to_string())),
|
||||||
|
CreateButton::new("unapprove_btn") .label("Disapprove") .emoji(ReactionType::Unicode("❌".to_string())),
|
||||||
|
CreateButton::new("remove_btn") .label("Remove") .emoji(ReactionType::Unicode("🗑️".to_string()))
|
||||||
|
]);
|
||||||
|
|
||||||
return EmbedOptions {
|
return EmbedOptions {
|
||||||
title: Some(post_data["post_data"]["title"].as_str().unwrap().to_string()),
|
title: Some(post_data["post_data"]["title"].as_str().unwrap().to_string()),
|
||||||
desc: format!("{}\n\nJSON: ||`{}`||", trimmed, serde_json::to_string(&json_min).unwrap()),
|
desc: format!("{}\n\nJSON: ||`{}`||", trimmed, serde_json::to_string(&json_min).unwrap()),
|
||||||
@@ -232,6 +252,7 @@ pub fn make_post_embed(post_data: &Value, url: &str, ephemeral: bool) -> EmbedOp
|
|||||||
thumbnail: media_urls.first()
|
thumbnail: media_urls.first()
|
||||||
.and_then(|url| url.as_str().map(|s| s.to_string()))
|
.and_then(|url| url.as_str().map(|s| s.to_string()))
|
||||||
.or(None),
|
.or(None),
|
||||||
|
actionrows: Some(vec![action_row]),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub async fn cmd(
|
|||||||
send_msg(ctx, lang!("dc_msg_bound_channel", c_id), true, true).await;
|
send_msg(ctx, lang!("dc_msg_bound_channel", c_id), true, true).await;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
send_msg(ctx, lang!("dc_msg_server_data_404"), false, false).await;
|
send_msg(ctx, lang!("dc_msg_data_server_404"), true, true).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ pub fn to_shorturl(url: &str) -> Result<String, &str> {
|
|||||||
|
|
||||||
pub async fn send_embed_for_post(ctx: Context<'_>, post: Value, url: &str) -> Result<(), Error> {
|
pub async fn send_embed_for_post(ctx: Context<'_>, post: Value, url: &str) -> Result<(), Error> {
|
||||||
send_embed(ctx, make_post_embed(&post, url, true), true).await;
|
send_embed(ctx, make_post_embed(&post, url, true), true).await;
|
||||||
Ok(())
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_embed_for_removed(ctx: Context<'_>, url: &str, post: &Value) {
|
pub async fn send_embed_for_removed(ctx: Context<'_>, url: &str, post: &Value) {
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ async fn update_progress(ctx: Context<'_>, p: ReplyHandle<'_>, t: String, added_
|
|||||||
|
|
||||||
async fn get_c_id(ctx: Context<'_>) -> Option<ChannelId> {
|
async fn get_c_id(ctx: Context<'_>) -> Option<ChannelId> {
|
||||||
if !data::dc_contains_server(ctx.data(), ctx.guild_id().unwrap().into()).await {
|
if !data::dc_contains_server(ctx.data(), ctx.guild_id().unwrap().into()).await {
|
||||||
send_msg(ctx, lang!("dc_msg_server_data_404"), false, false).await;
|
send_msg(ctx, lang!("dc_msg_data_server_404"), true, true).await;
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user