-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #166 from pulcher/add_re_roll_redeem
Add re roll redeem
- Loading branch information
Showing
3 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
Magic8HeadService/MqttHandlers/Redeems/ReRollVoiceHandler .cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.Extensions.Logging; | ||
using System.Linq; | ||
using TwitchLib.Client.Interfaces; | ||
using System.Text.Json; | ||
using System.Text; | ||
|
||
namespace Magic8HeadService.MqttHandlers.Redeems | ||
{ | ||
public class ReRollVoiceHandler : IMqttHandler | ||
{ | ||
private ITwitchClient client; | ||
private readonly ISayingResponse sayingResponse; | ||
private ILogger<Worker> logger; | ||
|
||
public ReRollVoiceHandler(ITwitchClient client, ISayingResponse sayingResponse, ILogger<Worker> logger) | ||
{ | ||
this.client = client; | ||
this.sayingResponse = sayingResponse; | ||
this.logger = logger; | ||
} | ||
|
||
public bool CanHandle(MqttHandlerMessage message) | ||
{ | ||
if (message == null) return false; | ||
|
||
var payloadString = Encoding.ASCII.GetString(message.Payload); | ||
|
||
var redeem = JsonSerializer.Deserialize<MqttRedeemPayload>(payloadString); | ||
|
||
if (redeem != null && redeem.RewardName == "Voice Lottery Ticket") | ||
return true; | ||
else | ||
return false; | ||
} | ||
|
||
public void Handle(MqttHandlerMessage message) | ||
{ | ||
var payloadString = Encoding.ASCII.GetString(message.Payload); | ||
var redeem = JsonSerializer.Deserialize<MqttRedeemPayload>(payloadString); | ||
var messageToSay = $"Hey Programs guess who is getting a new voice? {redeem.UserName} is cuz they are a big baby!"; | ||
|
||
if (!sayingResponse.ResetVoiceForUser(redeem.UserName)) | ||
{ | ||
messageToSay = $"Hey {redeem.UserName}! You need to get one first! You do that by subscribing! SHOW ME THE MONEY!"; | ||
} | ||
|
||
sayingResponse.SaySomethingNiceAsync(messageToSay, client, | ||
client.JoinedChannels.FirstOrDefault().ToString(), string.Empty).Wait(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters