Skip to content

Commit ee0bc5e

Browse files
authored
Merge pull request #136 from MostroP2P/improving-context
Improving context
2 parents 4914787 + 2a41839 commit ee0bc5e

File tree

4 files changed

+30
-34
lines changed

4 files changed

+30
-34
lines changed

cliff.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ topo_order = false
9797
# Order of commits in each group/release within the changelog.
9898
# Allowed values: newest, oldest
9999
sort_commits = "newest"
100-
# Enable link parsing for PR references
100+
# Enable link parsing for PR references and user mentions
101101
link_parsers = [
102102
{ pattern = "Merge pull request #([0-9]+)", href = "https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}/pull/$1" },
103103
{ pattern = "#([0-9]+)", href = "https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}/pull/$1" },
104+
{ pattern = "@([a-zA-Z0-9_-]+(?:\\[[^\\]]+\\])?)", href = "https://github.com/$1" },
104105
]

src/cli.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,7 @@ impl Commands {
423423
pubkey,
424424
order_id,
425425
message,
426-
} => {
427-
execute_send_dm(PublicKey::from_str(pubkey)?, &ctx.client, order_id, message).await
428-
}
426+
} => execute_send_dm(PublicKey::from_str(pubkey)?, ctx, order_id, message).await,
429427
Commands::DmToUser {
430428
pubkey,
431429
order_id,
@@ -441,7 +439,7 @@ impl Commands {
441439
.await
442440
}
443441
Commands::AdmSendDm { pubkey, message } => {
444-
execute_adm_send_dm(PublicKey::from_str(pubkey)?, &ctx.client, message).await
442+
execute_adm_send_dm(PublicKey::from_str(pubkey)?, ctx, message).await
445443
}
446444
Commands::ConversationKey { pubkey } => {
447445
execute_conversation_key(&ctx.trade_keys, PublicKey::from_str(pubkey)?).await

src/cli/adm_send_dm.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1+
use crate::cli::Context;
12
use crate::util::send_admin_gift_wrap_dm;
23
use anyhow::Result;
34
use nostr_sdk::prelude::*;
45

5-
pub async fn execute_adm_send_dm(
6-
receiver: PublicKey,
7-
client: &Client,
8-
message: &str,
9-
) -> Result<()> {
10-
let admin_keys = match std::env::var("NSEC_PRIVKEY") {
11-
Ok(key) => Keys::parse(&key)?,
12-
Err(e) => {
13-
anyhow::bail!("NSEC_PRIVKEY not set: {e}");
14-
}
15-
};
16-
6+
pub async fn execute_adm_send_dm(receiver: PublicKey, ctx: &Context, message: &str) -> Result<()> {
177
println!(
188
"SENDING DM with admin keys: {}",
19-
admin_keys.public_key().to_hex()
9+
ctx.context_keys.public_key().to_hex()
2010
);
2111

22-
send_admin_gift_wrap_dm(client, &admin_keys, &receiver, message).await?;
12+
send_admin_gift_wrap_dm(&ctx.client, &ctx.context_keys, &receiver, message).await?;
2313

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

src/cli/send_dm.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::cli::Context;
12
use crate::{db::Order, util::send_dm};
23
use anyhow::Result;
34
use mostro_core::prelude::*;
@@ -6,7 +7,7 @@ use uuid::Uuid;
67

78
pub async fn execute_send_dm(
89
receiver: PublicKey,
9-
client: &Client,
10+
ctx: &Context,
1011
order_id: &Uuid,
1112
message: &str,
1213
) -> Result<()> {
@@ -19,22 +20,28 @@ pub async fn execute_send_dm(
1920
.as_json()
2021
.map_err(|_| anyhow::anyhow!("Failed to serialize message"))?;
2122

22-
let pool = crate::db::connect().await?;
23-
24-
let trade_keys = if let Ok(order_to_vote) = Order::get_by_id(&pool, &order_id.to_string()).await
25-
{
26-
match order_to_vote.trade_keys.as_ref() {
27-
Some(trade_keys) => Keys::parse(trade_keys)?,
28-
None => {
29-
anyhow::bail!("No trade_keys found for this order");
23+
let trade_keys =
24+
if let Ok(order_to_vote) = Order::get_by_id(&ctx.pool, &order_id.to_string()).await {
25+
match order_to_vote.trade_keys.as_ref() {
26+
Some(trade_keys) => Keys::parse(trade_keys)?,
27+
None => {
28+
anyhow::bail!("No trade_keys found for this order");
29+
}
3030
}
31-
}
32-
} else {
33-
println!("order {} not found", order_id);
34-
std::process::exit(0)
35-
};
31+
} else {
32+
return Err(anyhow::anyhow!("order {} not found", order_id));
33+
};
3634

37-
send_dm(client, None, &trade_keys, &receiver, message, None, false).await?;
35+
send_dm(
36+
&ctx.client,
37+
None,
38+
&trade_keys,
39+
&receiver,
40+
message,
41+
None,
42+
false,
43+
)
44+
.await?;
3845

3946
Ok(())
4047
}

0 commit comments

Comments
 (0)