-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSC_TmiMessageParser.cs
More file actions
68 lines (56 loc) · 2.35 KB
/
SC_TmiMessageParser.cs
File metadata and controls
68 lines (56 loc) · 2.35 KB
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
using System;
using System.Collections.Generic;
// Class to parse Twitch IRC message with special capabilities
// Sample message :
//
// @badge - info = subscriber / 8;
// badges = broadcaster / 1,subscriber / 0,premium / 1;
// client - nonce = 613504e2dc98c210973e64b6d6e56d9d;
// color =#8A2BE2;
// display-name=Aqueuse;
// emotes=;
// first-msg=0;
// flags=;
// id=4893b988-1cf9-4f42-a28b-7a77011600eb;
// mod=0;
// room-id=462818643;subscriber=1;
// tmi-sent-ts=1654694579465;
// turbo=0;
// user-id=462818643;
// user-type= :aqueuse!aqueuse@aqueuse.tmi.twitch.tv PRIVMSG #aqueuse :plop
public class SC_TmiMessageParser {
public static Dictionary<string, string> parsedMessage(string rawMessage) {
Dictionary<string, string> parsedMessage = new Dictionary<string, string>();
string[] dirtyMessage = rawMessage.Split("!");
if (dirtyMessage.Length < 2) {
Console.WriteLine("incorrect message, can't parsed it");
return parsedMessage;
}
else {
string[] messageParameters = dirtyMessage[0].Split(";");
if (messageParameters.Length > 0) {
for (int i = 0; i < messageParameters.Length; i++) {
string[] parameter = messageParameters[i].Split("=");
if (parameter.Length == 1) {
parsedMessage.Add(parameter[0].Replace(" ", ""), null);
}
else {
parsedMessage.Add(parameter[0].Replace(" ", ""), parameter[1].Trim());
}
}
}
}
Console.WriteLine(rawMessage.Substring(rawMessage.IndexOf("!")));
parsedMessage.Add("IRC-message", rawMessage.Substring(rawMessage.IndexOf("!")));
return parsedMessage;
}
// !aqueuse@aqueuse.tmi.twitch.tv PRIVMSG #aqueuse :plop
public static Dictionary<string, string> parsedPRIVMSG(string rawPRIVMSG) {
Dictionary <string, string> parsedPRIVMSG = new Dictionary<string, string>();
string username = rawPRIVMSG.Substring(1, rawPRIVMSG.IndexOf("@") - 1);
string message = rawPRIVMSG.Substring(rawPRIVMSG.IndexOf(":") + 1);
parsedPRIVMSG.Add("username", username);
parsedPRIVMSG.Add("message", message);
return parsedPRIVMSG;
}
}