Skip to content
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
3 changes: 2 additions & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ topo_order = false
# Order of commits in each group/release within the changelog.
# Allowed values: newest, oldest
sort_commits = "newest"
# Enable link parsing for PR references
# Enable link parsing for PR references and user mentions
link_parsers = [
{ pattern = "Merge pull request #([0-9]+)", href = "https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}/pull/$1" },
{ pattern = "#([0-9]+)", href = "https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}/pull/$1" },
{ pattern = "@([a-zA-Z0-9_-]+(?:\\[[^\\]]+\\])?)", href = "https://github.com/$1" },
]
6 changes: 2 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ impl Commands {
pubkey,
order_id,
message,
} => {
execute_send_dm(PublicKey::from_str(pubkey)?, &ctx.client, order_id, message).await
}
} => execute_send_dm(PublicKey::from_str(pubkey)?, ctx, order_id, message).await,
Commands::DmToUser {
pubkey,
order_id,
Expand All @@ -441,7 +439,7 @@ impl Commands {
.await
}
Commands::AdmSendDm { pubkey, message } => {
execute_adm_send_dm(PublicKey::from_str(pubkey)?, &ctx.client, message).await
execute_adm_send_dm(PublicKey::from_str(pubkey)?, ctx, message).await
}
Commands::ConversationKey { pubkey } => {
execute_conversation_key(&ctx.trade_keys, PublicKey::from_str(pubkey)?).await
Expand Down
18 changes: 4 additions & 14 deletions src/cli/adm_send_dm.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
use crate::cli::Context;
use crate::util::send_admin_gift_wrap_dm;
use anyhow::Result;
use nostr_sdk::prelude::*;

pub async fn execute_adm_send_dm(
receiver: PublicKey,
client: &Client,
message: &str,
) -> Result<()> {
let admin_keys = match std::env::var("NSEC_PRIVKEY") {
Ok(key) => Keys::parse(&key)?,
Err(e) => {
anyhow::bail!("NSEC_PRIVKEY not set: {e}");
}
};

pub async fn execute_adm_send_dm(receiver: PublicKey, ctx: &Context, message: &str) -> Result<()> {
println!(
"SENDING DM with admin keys: {}",
admin_keys.public_key().to_hex()
ctx.context_keys.public_key().to_hex()
);

send_admin_gift_wrap_dm(client, &admin_keys, &receiver, message).await?;
send_admin_gift_wrap_dm(&ctx.client, &ctx.context_keys, &receiver, message).await?;

println!("Admin gift wrap message sent to {}", receiver);

Expand Down
37 changes: 22 additions & 15 deletions src/cli/send_dm.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::cli::Context;
use crate::{db::Order, util::send_dm};
use anyhow::Result;
use mostro_core::prelude::*;
Expand All @@ -6,7 +7,7 @@ use uuid::Uuid;

pub async fn execute_send_dm(
receiver: PublicKey,
client: &Client,
ctx: &Context,
order_id: &Uuid,
message: &str,
) -> Result<()> {
Expand All @@ -19,22 +20,28 @@ pub async fn execute_send_dm(
.as_json()
.map_err(|_| anyhow::anyhow!("Failed to serialize message"))?;

let pool = crate::db::connect().await?;

let trade_keys = if let Ok(order_to_vote) = Order::get_by_id(&pool, &order_id.to_string()).await
{
match order_to_vote.trade_keys.as_ref() {
Some(trade_keys) => Keys::parse(trade_keys)?,
None => {
anyhow::bail!("No trade_keys found for this order");
let trade_keys =
if let Ok(order_to_vote) = Order::get_by_id(&ctx.pool, &order_id.to_string()).await {
match order_to_vote.trade_keys.as_ref() {
Some(trade_keys) => Keys::parse(trade_keys)?,
None => {
anyhow::bail!("No trade_keys found for this order");
}
}
}
} else {
println!("order {} not found", order_id);
std::process::exit(0)
};
} else {
return Err(anyhow::anyhow!("order {} not found", order_id));
};

send_dm(client, None, &trade_keys, &receiver, message, None, false).await?;
send_dm(
&ctx.client,
None,
&trade_keys,
&receiver,
message,
None,
false,
)
.await?;

Ok(())
}