Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugins #87

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions TwitchEverywhere.Benchmark/AccessBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using System.Text;
using BenchmarkDotNet.Attributes;
using TwitchEverywhere.Core;
using TwitchEverywhere.Core.Types;
using TwitchEverywhere.Core.Types.Messages;
using TwitchEverywhere.Core.Types.Messages.Interfaces;
using TwitchEverywhere.Irc;
using TwitchEverywhere.Irc.Implementation;

namespace TwitchEverywhere.Benchmark;

public class AccessBenchmark {
private readonly TwitchConnectionOptions m_options = new(
"channel",
"access_token",
"refresh_token",
"client_id",
"client_secret",
"client_name"
);

private IMessageProcessor processor = new MessageProcessor();
private IPrivMsg privMsg;

[GlobalSetup]
public void AddData() {
string message =
"@badge-info=;badges=turbo/1;color=#0D4200;display-name=ronni;emotes=25:0-4,12-16/1902:6-10;id=b34ccfc7-4977-403a-8a94-33c6bac34fb8;mod=0;room-id=1337;subscriber=0;tmi-sent-ts=1507246572675;turbo=1;user-id=1337;user-type=global_mod :[email protected] PRIVMSG #channel :Kappa Keepo Kappa";

byte[] byteArray = Encoding.UTF8.GetBytes( message );
processor.ProcessMessage( new RawMessage( byteArray ), "", BenchmarkCallback );
}

[Params( 3 )] public int Iterations;

[Benchmark]
public string Create() {
string text = string.Empty;
for( int i = 0; i < Iterations; i++ ) {
text = privMsg.Id;
}

return text;
}

private void BenchmarkCallback(
IMessage message
) {
switch( message.MessageType ) {
case MessageType.PrivMsg:
privMsg = (IPrivMsg)message;
break;
}
}
}
3 changes: 2 additions & 1 deletion TwitchEverywhere.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
using TwitchEverywhere.Benchmark;

// BenchmarkRunner.Run<RegexBenchmark>();
BenchmarkRunner.Run<Bandwidth>();
// BenchmarkRunner.Run<Bandwidth>();
BenchmarkRunner.Run<AccessBenchmark>();
18 changes: 16 additions & 2 deletions TwitchEverywhere.Core/MessagePluginUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static partial class MessagePluginUtils {
[GeneratedRegex("followers-only=([^ ;]*)", RegexOptions.NonBacktracking)]
public static partial Regex FollowersOnlyPattern();

[GeneratedRegex(@" :(.+?)!", RegexOptions.NonBacktracking)]
[GeneratedRegex(@"WHISPER\s(.*?) :[^:]*$", RegexOptions.NonBacktracking)]
public static partial Regex FromUserPattern();

[GeneratedRegex(@":([a-zA-Z-]+)(?=\s\d+)")]
Expand Down Expand Up @@ -182,7 +182,7 @@ public static partial class MessagePluginUtils {
[GeneratedRegex("thread-id=([^ ;]*)", RegexOptions.NonBacktracking)]
public static partial Regex ThreadIdPattern();

[GeneratedRegex(@"WHISPER\s(.*?) :[^:]*$", RegexOptions.NonBacktracking)]
[GeneratedRegex(@" :(.+?)!", RegexOptions.NonBacktracking)]
public static partial Regex ToUserPattern();

[GeneratedRegex("turbo=([^ ;]*)", RegexOptions.NonBacktracking)]
Expand Down Expand Up @@ -507,4 +507,18 @@ public static string GetChannelFromMessage( RawMessage message ) {
]
);
}

public static string GetTextFromMessage( RawMessage message ) {

if( !message.MessageContentRange.HasValue ) {
return string.Empty;
}

return Encoding.UTF8.GetString(
message.Data.Span[
message.MessageContentRange.Value.Start
..message.MessageContentRange.Value.End
]
).TrimEnd();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace TwitchEverywhere.Core.Types.Messages.ImmediateLoadedMessages;

public class ImmediateLoadedGlobalUserState : IGlobalUserState {
public class ImmediateLoadedGlobalUserStateMsg : IGlobalUserStateMsg {

private readonly IImmutableList<Badge> m_badges;
private readonly IImmutableList<Badge> m_badgeInfo;
Expand All @@ -16,7 +16,7 @@ public class ImmediateLoadedGlobalUserState : IGlobalUserState {
private readonly UserType m_userType;
private readonly string m_channel;

public ImmediateLoadedGlobalUserState(
public ImmediateLoadedGlobalUserStateMsg(
string channel,
IImmutableList<Badge>? badges = null,
IImmutableList<Badge>? badgeInfo = null,
Expand Down Expand Up @@ -44,21 +44,21 @@ public ImmediateLoadedGlobalUserState(

public string Channel => m_channel;

IImmutableList<Badge> IGlobalUserState.Badges => m_badges;
IImmutableList<Badge> IGlobalUserStateMsg.Badges => m_badges;

IImmutableList<Badge> IGlobalUserState.BadgeInfo => m_badgeInfo;
IImmutableList<Badge> IGlobalUserStateMsg.BadgeInfo => m_badgeInfo;

string IGlobalUserState.Color => m_color;
string IGlobalUserStateMsg.Color => m_color;

string IGlobalUserState.DisplayName => m_displayName;
string IGlobalUserStateMsg.DisplayName => m_displayName;

IImmutableList<string> IGlobalUserState.EmoteSets => m_emoteSets;
IImmutableList<string> IGlobalUserStateMsg.EmoteSets => m_emoteSets;

bool IGlobalUserState.Turbo => m_turbo;
bool IGlobalUserStateMsg.Turbo => m_turbo;

string IGlobalUserState.UserId => m_userId;
string IGlobalUserStateMsg.UserId => m_userId;

UserType IGlobalUserState.UserType => m_userType;
UserType IGlobalUserStateMsg.UserType => m_userType;

private string GetRawMessage() {
string message = "@";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace TwitchEverywhere.Core.Types.Messages.ImmediateLoadedMessages;

public class ImmediateLoadedUnknownMessage : IUnknownMessage {
public class ImmediateLoadedUnknownMsg : IUnknownMsg {
private readonly string m_message;

public ImmediateLoadedUnknownMessage(
public ImmediateLoadedUnknownMsg(
string channel,
string message
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using System.Collections.Immutable;
using TwitchEverywhere.Core.Types.Messages.Interfaces;
using TwitchEverywhere.Core.Types.Messages.LazyLoadedMessages;

namespace TwitchEverywhere.Core.Types.Messages.Implementation;

public class GlobalUserStateMsg : IGlobalUserStateMsg {
private MessageType m_messageType;
private string m_rawMessage;
private string m_channel;
private IImmutableList<Badge>? m_badges;
private IImmutableList<Badge>? m_badgeInfo;
private string m_color;
private string m_displayName;
private IImmutableList<string>? m_emoteSets;
private bool? m_turbo;
private string m_userId;
private UserType? m_userType;
private readonly IGlobalUserStateMsg m_inner;

public GlobalUserStateMsg(
RawMessage message
) {
m_inner = new LazyLoadedGlobalUserStateMsg( message );
}

MessageType IMessage.MessageType => MessageType.GlobalUserState;

string IMessage.RawMessage {
get {
if (string.IsNullOrEmpty(m_rawMessage)) {
m_rawMessage = m_inner.RawMessage;
}
return m_rawMessage;
}
}

string IMessage.Channel {
get {
if (string.IsNullOrEmpty(m_channel)) {
m_channel = m_inner.Channel;
}
return m_channel;
}
}

IImmutableList<Badge> IGlobalUserStateMsg.Badges {
get {
m_badges ??= m_inner.Badges;
return m_badges;
}
}

IImmutableList<Badge> IGlobalUserStateMsg.BadgeInfo {
get {
m_badgeInfo ??= m_inner.BadgeInfo;
return m_badgeInfo;
}
}

string IGlobalUserStateMsg.Color {
get {
if (string.IsNullOrEmpty(m_color)) {
m_color = m_inner.Color;
}
return m_color;
}
}

string IGlobalUserStateMsg.DisplayName {
get {
if (string.IsNullOrEmpty(m_displayName)) {
m_displayName = m_inner.DisplayName;
}
return m_displayName;
}
}

IImmutableList<string> IGlobalUserStateMsg.EmoteSets {
get {
m_emoteSets ??= m_inner.EmoteSets;
return m_emoteSets;
}
}

bool IGlobalUserStateMsg.Turbo {
get {
m_turbo ??= m_inner.Turbo;
return m_turbo.Value;
}
}

string IGlobalUserStateMsg.UserId {
get {
if (string.IsNullOrEmpty(m_userId)) {
m_userId = m_inner.UserId;
}
return m_userId;
}
}

UserType IGlobalUserStateMsg.UserType {
get {
m_userType ??= m_inner.UserType;
return m_userType.Value;
}
}
}
38 changes: 38 additions & 0 deletions TwitchEverywhere.Core/Types/Messages/Implementation/JoinCount.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using TwitchEverywhere.Core.Types.Messages.Interfaces;
using TwitchEverywhere.Core.Types.Messages.LazyLoadedMessages;

namespace TwitchEverywhere.Core.Types.Messages.Implementation;

public class JoinCount : IJoinCountMsg {
private MessageType m_messageType;
private string m_rawMessage;
private string m_channel;
private readonly IJoinCountMsg m_inner;

public JoinCount(
RawMessage message
) {
m_inner = new LazyLoadedJoinCountMsg( message );
}

MessageType IMessage.MessageType => MessageType.JoinCount;

string IMessage.RawMessage {
get {
if( string.IsNullOrEmpty( m_rawMessage ) ) {
m_rawMessage = m_inner.RawMessage;
}
return m_rawMessage;
}
}

string IMessage.Channel {
get {
if( string.IsNullOrEmpty( m_channel ) ) {
m_channel = m_inner.Channel;
}
return m_channel;
}

}
}
49 changes: 49 additions & 0 deletions TwitchEverywhere.Core/Types/Messages/Implementation/PartMsg.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using TwitchEverywhere.Core.Types.Messages.Interfaces;
using TwitchEverywhere.Core.Types.Messages.LazyLoadedMessages;

namespace TwitchEverywhere.Core.Types.Messages.Implementation;

public class PartMsg : IPartMsg {
private MessageType m_messageType;
private string m_rawMessage;
private string m_channel;
private string m_user;
private readonly IPartMsg m_inner;

public PartMsg(
RawMessage message
) {
m_inner = new LazyLoadedPartMsg( message );
}

MessageType IMessage.MessageType => MessageType.Part;

string IMessage.RawMessage {
get {
if( string.IsNullOrEmpty( m_rawMessage ) ) {
m_rawMessage = m_inner.RawMessage;
}
return m_rawMessage;
}
}

string IMessage.Channel {
get {
if( string.IsNullOrEmpty( m_channel ) ) {
m_channel = m_inner.Channel;
}
return m_channel;
}

}

string IPartMsg.User {
get {
if( string.IsNullOrEmpty( m_user ) ) {
m_user = m_inner.User;
}

return m_user;
}
}
}
Loading
Loading