Skip to content

Commit

Permalink
add share button #2
Browse files Browse the repository at this point in the history
return Ru localization for attrs and fn
  • Loading branch information
TOwInOK committed Sep 14, 2024
1 parent 6120531 commit 98ecde2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/boop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{Context, Error};
use poise::{serenity_prelude as serenity, CreateReply};

/// Boop the bot!
#[poise::command(prefix_command, track_edits, slash_command)]
#[poise::command(prefix_command, track_edits, slash_command, nsfw_only)]
pub async fn boop(ctx: Context<'_>) -> Result<(), Error> {
let uuid_boop = ctx.id();

Expand Down
25 changes: 14 additions & 11 deletions src/image_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ static LEN_MAX: usize = 30;
guild_only,
nsfw_only,
description_localized("ru", "Получить дозу эмоций"),
// name_localized("ru", "порно"),
name_localized("ru", "порно"),
ephemeral
)]
pub async fn porno(
ctx: Context<'_>,
#[description = "let me your favorite tags!"]
#[description_localized("ru", "Дай мне свои любимые теги")]
// #[name_localized("ru", "позитивные теги")]
#[name_localized("ru", "позитивные_теги")]
// #[name_localized("us", "positive tags")]
positive_tags: Option<String>,
#[description = "let me your unfavorite tags!"]
#[description_localized("ru", "Что не нравится?")]
// #[name_localized("ru", "негативные теги")]
#[name_localized("ru", "негативные_теги")]
// #[name_localized("us", "negative tags")]
negative_tags: Option<String>,
#[description = "Do you wana some special?!"]
#[description = "Do you wanna some special?!"]
#[description_localized("ru", "Позвони и узнай, как там с деньгами!")]
// #[name_localized("ru", "пробив по номеру")]
#[name_localized("ru", "пробив_по_номеру")]
id: Option<usize>,
#[description = "How many do you want?"]
#[description_localized("ru", "Сколько выдать?")]
// #[name_localized("ru", "количество")]
#[name_localized("ru", "количество")]
size: Option<usize>,
) -> Result<(), Error> {
let mut posts = vec![];
Expand Down Expand Up @@ -68,11 +68,14 @@ pub async fn porno(
}
} else {
info!("Nothing addition params found");
for _ in 0..size {
match R34!(R; D) {
Ok(data) => posts.push(data.data()[0].clone()),
Err(_) => continue,
}
match shuller::rules::rule34::params::R34Params::init()
.page(random_usize!(u16::MAX as usize) as u16)
.limit(size as u16)
.download()
.await
{
Ok(data) => posts.append(&mut data.data()),
Err(_) => return Err("**Error: Posts** not found".into()),
}
}

Expand Down
99 changes: 63 additions & 36 deletions src/paginate.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use crate::{phrazes::PHRAZES, Context};
// use phrazes;
use crate::{phrazes::PHRASES, Context};
use ::serenity::all::{CreateMessage, ReactionType};
use poise::{serenity_prelude as serenity, CreateReply};
use shuller::{prelude::Post, random_usize};
use tracing::info;

pub async fn paginate(ctx: Context<'_>, posts: &[Post]) -> Result<(), crate::Error> {
// Define some unique identifiers for the navigation buttons
let ctx_id = ctx.id();
let mut current_page = 0;
let buttons = |x: &usize| {
let buttons = |current_num: &usize| {
let mut vec = vec![];
if posts.len() != 1 {
for num in 0..posts.len() {
vec.push(if x == &num {
posts.iter().enumerate().for_each(|(num, _)| {
vec.push(if current_num == &num {
serenity::CreateButton::new(format!("{}-{}", ctx_id, num))
.label(format!("{}", num + 1))
.style(serenity::ButtonStyle::Success)
Expand All @@ -21,67 +20,95 @@ pub async fn paginate(ctx: Context<'_>, posts: &[Post]) -> Result<(), crate::Err
.label(format!("{}", num + 1))
.style(serenity::ButtonStyle::Secondary)
})
}
})
} else {
vec.push(
serenity::CreateButton::new(format!("{}-{}", ctx_id, 0))
.label(format!("{}", posts[0].id))
.style(serenity::ButtonStyle::Success),
);
}
vec.push(
serenity::CreateButton::new(format!("{}-send_to_chat", ctx_id))
.emoji(ReactionType::Unicode("🚀".to_string()))
.style(serenity::ButtonStyle::Primary),
);
vec
};

let post = |page: &usize| {
let post = |page: &usize, shared: bool| {
info!("page is: {:#?}", &posts[*page]);
serenity::CreateEmbed::default()
.image(&posts[*page].sample_url)
.url(&posts[*page].file_url)
.title(PHRAZES[random_usize!(PHRAZES.len())])
.color(serenity::Colour::from_rgb(
random_usize!(255) as u8,
random_usize!(255) as u8,
random_usize!(255) as u8,
))
.description(format!(
"**Tags:**
match shared {
true => serenity::CreateEmbed::default()
.image(&posts[*page].sample_url)
.url(&posts[*page].file_url)
.title(PHRASES[random_usize!(PHRASES.len())])
.color(serenity::Colour::from_rgb(
random_usize!(255) as u8,
random_usize!(255) as u8,
random_usize!(255) as u8,
))
.description(format!(
"**Tags:**
{}",
&posts[*page].tags
))
.author(serenity::CreateEmbedAuthor::new(&posts[*page].owner))
&posts[*page].tags
))
.author(serenity::CreateEmbedAuthor::new(&posts[*page].owner))
.footer(
serenity::CreateEmbedFooter::new(format!("shared by: {}", ctx.author().name))
.icon_url(ctx.author().avatar_url().unwrap_or_default()),
),
false => serenity::CreateEmbed::default()
.image(&posts[*page].sample_url)
.url(&posts[*page].file_url)
.title(PHRASES[random_usize!(PHRASES.len())])
.color(serenity::Colour::from_rgb(
random_usize!(255) as u8,
random_usize!(255) as u8,
random_usize!(255) as u8,
))
.description(format!(
"**Tags:**
{}",
&posts[*page].tags
))
.author(serenity::CreateEmbedAuthor::new(&posts[*page].owner)),
}
};
// Send the embed with the first page as content
let reply = {
let components = serenity::CreateActionRow::Buttons(buttons(&current_page));

CreateReply::default()
.embed(post(&current_page))
.embed(post(&current_page, false))
.components(vec![components])
};

ctx.send(reply).await?;

// Loop through incoming interactions with the navigation buttons
while let Some(press) = serenity::collector::ComponentInteractionCollector::new(ctx)
// We defined our button IDs to start with `ctx_id`. If they don't, some other command's
// button was pressed
.filter(move |press| press.data.custom_id.starts_with(&ctx_id.to_string()))
// Timeout when no navigation button has been pressed for 1 hours
.timeout(std::time::Duration::from_secs(3600))
.timeout(std::time::Duration::from_secs(60 * 60))
.await
{
// Depending on which button was pressed, go to next or previous page
current_page = {
let temp: Vec<&str> = press.data.custom_id.split("-").collect();
temp[1].parse().unwrap_or(0)
};
// Update the message with the new page contents
if press.data.custom_id == format!("{}-send_to_chat", ctx_id) {
ctx.channel_id()
.send_message(
&ctx.http(),
CreateMessage::new().embed(post(&current_page, true)),
)
.await?;
} else {
current_page = {
let temp: Vec<&str> = press.data.custom_id.split("-").collect();
temp[1].parse().unwrap_or(0)
};
}
press
.create_response(
ctx.serenity_context(),
serenity::CreateInteractionResponse::UpdateMessage(
serenity::CreateInteractionResponseMessage::new()
.embed(post(&current_page))
.embed(post(&current_page, false))
.components(vec![serenity::CreateActionRow::Buttons(buttons(
&current_page,
))]),
Expand Down
2 changes: 1 addition & 1 deletion src/phrazes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub const PHRAZES: [&str; 1690] = [
pub const PHRASES: [&str; 1690] = [
"Look at full picture!",
"Be honor, check this!",
"Ohhh, that what I'm wating for",
Expand Down

0 comments on commit 98ecde2

Please sign in to comment.