feat: refund more

This commit is contained in:
Anna 2022-03-20 00:41:12 -04:00
parent add0e4197b
commit 58718263d7
Signed by: anna
GPG Key ID: 0B391D8F06FCD9E0
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) {
let input = match &redemption.user_input {
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("=>")
.or_else(|| input.split_once("->"))
{
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()
@ -220,6 +232,12 @@ async fn rename_a_split(state: Arc<State>, redemption: &Redemption) {
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()
.broadcaster_id(state.user_config.twitch.channel_id.to_string())
.reward_id(redemption.reward.id.clone())
@ -230,11 +248,11 @@ async fn rename_a_split(state: Arc<State>, redemption: &Redemption) {
.status(status)
.build();
if let Ok(token) = state.twitch.user_token().await {
if let Err(e) = state.twitch.client.helix.req_patch(req, body, &token).await {
eprintln!("could not update redemption status: {:?}", e);
}
}
let token = state.twitch.user_token().await?;
state.twitch.client.helix.req_patch(req, body, &token).await
.context("could not update redemption status")?;
Ok(())
}
async fn handle_channel_points_reply(state: Arc<State>, reply: Box<ChannelPointsChannelV1Reply>) -> anyhow::Result<()> {