feat: refund more

This commit is contained in:
Anna 2022-03-20 00:41:12 -04:00
parent 27d6997fc9
commit 0d3de07d65
1 changed files with 25 additions and 7 deletions

View File

@ -191,13 +191,25 @@ pub async fn handle_pubsub(state: Arc<State>, event: WsMessage) -> anyhow::Resul
async fn rename_a_split(state: Arc<State>, redemption: &Redemption) { async fn rename_a_split(state: Arc<State>, redemption: &Redemption) {
let input = match &redemption.user_input { let input = match &redemption.user_input {
Some(i) => i, Some(i) => i,
None => return, None => {
if let Err(e) = update_redemption_status(&*state, &redemption, CustomRewardRedemptionStatus::Canceled).await {
eprintln!("could not update redemption status: {:?}", e);
}
return;
}
}; };
let (old, new) = match input.split_once("=>") let (old, new) = match input.split_once("=>")
.or_else(|| input.split_once("->")) .or_else(|| input.split_once("->"))
{ {
Some(x) => x, Some(x) => x,
None => return, None => {
if let Err(e) = update_redemption_status(&*state, &redemption, CustomRewardRedemptionStatus::Canceled).await {
eprintln!("could not update redemption status: {:?}", e);
}
return;
}
}; };
let fulfilled = match reqwest::Client::new() let fulfilled = match reqwest::Client::new()
@ -220,6 +232,12 @@ async fn rename_a_split(state: Arc<State>, redemption: &Redemption) {
CustomRewardRedemptionStatus::Canceled CustomRewardRedemptionStatus::Canceled
}; };
if let Err(e) = update_redemption_status(&*state, &redemption, status).await {
eprintln!("could not update redemption status: {:?}", e);
}
}
async fn update_redemption_status(state: &State, redemption: &Redemption, status: CustomRewardRedemptionStatus) -> anyhow::Result<()> {
let req = UpdateRedemptionStatusRequest::builder() let req = UpdateRedemptionStatusRequest::builder()
.broadcaster_id(state.user_config.twitch.channel_id.to_string()) .broadcaster_id(state.user_config.twitch.channel_id.to_string())
.reward_id(redemption.reward.id.clone()) .reward_id(redemption.reward.id.clone())
@ -230,11 +248,11 @@ async fn rename_a_split(state: Arc<State>, redemption: &Redemption) {
.status(status) .status(status)
.build(); .build();
if let Ok(token) = state.twitch.user_token().await { let token = state.twitch.user_token().await?;
if let Err(e) = state.twitch.client.helix.req_patch(req, body, &token).await { state.twitch.client.helix.req_patch(req, body, &token).await
eprintln!("could not update redemption status: {:?}", e); .context("could not update redemption status")?;
}
} Ok(())
} }
async fn handle_channel_points_reply(state: Arc<State>, reply: Box<ChannelPointsChannelV1Reply>) -> anyhow::Result<()> { async fn handle_channel_points_reply(state: Arc<State>, reply: Box<ChannelPointsChannelV1Reply>) -> anyhow::Result<()> {