-
Notifications
You must be signed in to change notification settings - Fork 62
/
UserState.cs
111 lines (106 loc) · 4.63 KB
/
UserState.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System;
using System.Collections.Generic;
using System.Linq;
using TwitchLib.Client.Enums;
using TwitchLib.Client.Models.Internal;
namespace TwitchLib.Client.Models
{
/// <summary>Class representing state of a specific user.</summary>
public class UserState
{
/// <summary>Properrty representing the chat badges a specific user has.</summary>
public List<KeyValuePair<string, string>> Badges { get; } = new List<KeyValuePair<string, string>>();
/// <summary>Property representing channel.</summary>
public string Channel { get; }
/// <summary>Properrty representing HEX user's name.</summary>
public string ColorHex { get; }
/// <summary>Property representing user's display name.</summary>
public string DisplayName { get; }
/// <summary>Property representing emote sets available to user.</summary>
public string EmoteSet { get; }
/// <summary>Property representing Turbo status.</summary>
public bool IsModerator { get; }
/// <summary>Property representing subscriber status.</summary>
public bool IsSubscriber { get; }
/// <summary>Property representing returned user type of user.</summary>
public UserType UserType { get; }
/// <summary>
/// Constructor for UserState.
/// </summary>
/// <param name="ircMessage"></param>
public UserState(IrcMessage ircMessage)
{
Channel = ircMessage.Channel;
foreach (var tag in ircMessage.Tags.Keys)
{
var tagValue = ircMessage.Tags[tag];
switch (tag)
{
case Tags.Badges:
if (tagValue.Contains('/'))
{
if (!tagValue.Contains(","))
Badges.Add(new KeyValuePair<string, string>(tagValue.Split('/')[0], tagValue.Split('/')[1]));
else
foreach (var badge in tagValue.Split(','))
Badges.Add(new KeyValuePair<string, string>(badge.Split('/')[0], badge.Split('/')[1]));
}
break;
case Tags.Color:
ColorHex = tagValue;
break;
case Tags.DisplayName:
DisplayName = tagValue;
break;
case Tags.EmotesSets:
EmoteSet = tagValue;
break;
case Tags.Mod:
IsModerator = Common.Helpers.ConvertToBool(tagValue);
break;
case Tags.Subscriber:
IsSubscriber = Common.Helpers.ConvertToBool(tagValue);
break;
case Tags.UserType:
switch (tagValue)
{
case "mod":
UserType = UserType.Moderator;
break;
case "global_mod":
UserType = UserType.GlobalModerator;
break;
case "admin":
UserType = UserType.Admin;
break;
case "staff":
UserType = UserType.Staff;
break;
default:
UserType = UserType.Viewer;
break;
}
break;
default:
// This should never happen, unless Twitch changes their shit
Console.WriteLine($"Unaccounted for [UserState]: {tag}");
break;
}
}
if (string.Equals(ircMessage.User, Channel, StringComparison.InvariantCultureIgnoreCase))
UserType = UserType.Broadcaster;
}
public UserState(List<KeyValuePair<string, string>> badges, string colorHex, string displayName, string emoteSet, string channel,
bool isSubscriber, bool isModerator, UserType userType)
{
Badges = badges;
ColorHex = colorHex;
DisplayName = displayName;
EmoteSet = emoteSet;
Channel = channel;
IsSubscriber = isSubscriber;
IsModerator = isModerator;
UserType = UserType;
}
}
}