Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add emoji-steal #131

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.postgres.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3"
services:
postgres:
image: postgres
image: postgres:15
restart: always
ports:
- 5432:5432
Expand Down
9 changes: 9 additions & 0 deletions src/core/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ lazy_static! {
channel: None,
usage: "@BOT check_calendar <date = MM/AAAA>",
permission: Role::User,
},
"emoji-steal" =>
Command {
exec: emoji::emoji_steal,
argument_min: 0,
argument_max: 0,
channel: None,
usage: "@BOT emoji-steal (expected to be used as a reply to a message containing an emoji)",
permission: Role::User,
}
];
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/slash_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pub async fn handle_event(interaction: Interaction, ctx: Context) {
.unwrap()
}
"office-week" => {
let month = (Utc::now().iso_week().week() + 2) % 4;
let month = (Utc::now().iso_week().week() + 1) % 3 + 1;
let result = format!("it's currently S0{month}");
command
.create_interaction_response(&ctx.http, |res| {
Expand All @@ -108,7 +108,7 @@ pub async fn handle_event(interaction: Interaction, ctx: Context) {

#[test]
fn test_office_week() {
let month = (Utc::now().iso_week().week() + 2) % 4;
let month = (Utc::now().iso_week().week() + 1) % 3 + 1;
dbg!(month);
//
}
41 changes: 41 additions & 0 deletions src/features/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,44 @@ pub async fn add(params: CallBackParams<'_>) -> CallbackReturn {
Ok(Some(String::from("I am not able to get this emoji")))
}
}

#[command]
pub async fn emoji_steal(params: CallBackParams<'_>) -> CallbackReturn {
match &params.message.message_reference {
None => Ok(Some(String::from("This message is not a reply"))),
Some(message) => {
let message_content = params
.context
.http
.get_message(message.channel_id.0, message.message_id.unwrap().0)
.await
.expect("Expected a recent message to be in the cache");

if let Some((is_animated, emoji_name, emoji_id)) = emoji_str_convert(&message_content.content)
{
let extension = if is_animated { "gif" } else { "png" };
let url = format!(
"https://cdn.discordapp.com/emojis/{}.{}?size=128",
emoji_id, extension
);

let client = reqwest::Client::builder().build()?;
let response = client.get(url).send().await.unwrap();
let response_body = response.bytes().await.unwrap();
let base64_img = format!(
"data:image/{};base64,{}",
extension,
base64::encode(response_body)
);

let guild = params.message.guild_id.unwrap_or(GuildId(GUILD_ID));
guild
.create_emoji(&params.context.http, emoji_name, &base64_img)
.await?;
Ok(Some(String::from(":ok:")))
} else {
Ok(Some(String::from("I am not able to get this emoji")))
}
}
}
}