-
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 #137 from pulcher/add_readlc
Add readlc
- Loading branch information
Showing
10 changed files
with
136 additions
and
31 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
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
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,62 @@ | ||
|
||
using Magic8HeadService; | ||
using Magic8HeadService.Services; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.Logging; | ||
using TwitchLib.Client; | ||
using TwitchLib.Client.Events; | ||
using TwitchLib.Client.Interfaces; | ||
|
||
public class ReadLcCommand : ICommandMbhToTwitch | ||
{ | ||
private readonly ITwitchClient client; | ||
private readonly IConfiguration config; | ||
private readonly IMessageStackService messageStackService; | ||
private readonly ISayingResponse sayingResponse; | ||
private readonly IMessageChecker messageChecker; | ||
private readonly ICommandTracker commandTracker; | ||
private readonly ILogger<Worker> logger; | ||
|
||
public string Name => "readlc"; | ||
|
||
public ReadLcCommand(ITwitchClient client, IConfiguration config, IMessageStackService messageStackService, | ||
ISayingResponse sayingResponse, IMessageChecker messageChecker, ICommandTracker commandTracker, | ||
ILogger<Worker> logger) | ||
{ | ||
this.client = client; | ||
this.config = config; | ||
this.messageStackService = messageStackService; | ||
this.sayingResponse = sayingResponse; | ||
this.messageChecker = messageChecker; | ||
this.commandTracker = commandTracker; | ||
this.logger = logger; | ||
} | ||
|
||
public void Handle(OnChatCommandReceivedArgs args) | ||
{ | ||
var lastMessage = messageStackService.GetNextMessage(); | ||
|
||
if (lastMessage is not null) | ||
{ | ||
if (lastMessage.IsSubscriber | ||
|| lastMessage.IsVip | ||
|| lastMessage.IsModerator) | ||
{ | ||
var username = lastMessage.Username; | ||
var channel = lastMessage.Channel; | ||
|
||
var commandTrackerEntity = commandTracker.Add(username, "readlc"); | ||
|
||
var message = $"Speaking for {username}: who typed {messageChecker.CheckMessage(lastMessage.Message)}"; | ||
|
||
sayingResponse.SaySomethingNiceAsync(message, client, channel, username) | ||
.Wait(); | ||
} | ||
else | ||
{ | ||
client.SendMessage(lastMessage.Channel, | ||
$"Hey {lastMessage.Username}, the readlc command is for subscribers and vips only."); | ||
} | ||
} | ||
} | ||
} |
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
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,11 @@ | ||
using TwitchLib.Client.Models; | ||
|
||
namespace Magic8HeadService | ||
{ | ||
public interface IMessageStackService | ||
{ | ||
ChatMessage GetNextMessage(); | ||
ChatMessage GetPreviousMessage(int previousIndex); | ||
void PutMessage(ChatMessage message); | ||
} | ||
} |
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,33 @@ | ||
using System.Collections.Generic; | ||
using TwitchLib.Client.Models; | ||
|
||
namespace Magic8HeadService | ||
{ | ||
public class MessageStackService : IMessageStackService | ||
{ | ||
private readonly Stack<ChatMessage> messageStack; | ||
|
||
public MessageStackService() | ||
{ | ||
messageStack = new Stack<ChatMessage>(30); | ||
} | ||
public ChatMessage GetNextMessage() | ||
{ | ||
messageStack.TryPop(out var result); | ||
return result; | ||
} | ||
|
||
public ChatMessage GetPreviousMessage(int previousIndex) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
|
||
public void PutMessage(ChatMessage message) | ||
{ | ||
if (message == null) return; | ||
|
||
messageStack.TrimExcess(); | ||
messageStack.Push(message); | ||
} | ||
} | ||
} |
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
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
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
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