IRC parsing, tokenization, and state handling in C#
1using IRCTokens;
2
3namespace IRCRobots;
4
5public class Server : IServer
6{
7 public string Name { get; set; }
8 public IBot Bot { get; set; }
9 public bool Disconnected { get; set; }
10 public ConnectionParams Params { get; set; }
11 public List<ICapability> DesiredCaps { get; set; }
12 public float LastRead { get; set; }
13
14 private int _sentCount = 0;
15
16 public Task<SentLine> SendRawAsync(string line, SendPriority priority = SendPriority.Medium) =>
17 SendAsync(new(line), priority);
18
19 public Task<SentLine> SendAsync(Line line, SendPriority priority = SendPriority.Medium)
20 {
21 LinePresend(line);
22 var sentLine = new SentLine(_sentCount++, priority, line);
23
24 var label = CapAvailable(CAP_LABEL);
25 if (label is not null)
26 {
27 }
28 }
29
30 public Task<Line> WaitForAsync()
31 {
32 throw new NotImplementedException();
33 }
34
35 public void SetThrottle(int rate, float time)
36 {
37 throw new NotImplementedException();
38 }
39
40 public (string, int) ServerAddress()
41 {
42 throw new NotImplementedException();
43 }
44
45 public Task ConnectAsync(ITcpTransport transport, ConnectionParams connectionParams)
46 {
47 throw new NotImplementedException();
48 }
49
50 public Task DisconnectAsync()
51 {
52 throw new NotImplementedException();
53 }
54
55 public void LinePreread(Line line)
56 {
57 throw new NotImplementedException();
58 }
59
60 public void LinePresend(Line line)
61 {
62 throw new NotImplementedException();
63 }
64
65 public Task LineReadAsync(Line line)
66 {
67 throw new NotImplementedException();
68 }
69
70 public Task LineSendAsync(Line line)
71 {
72 throw new NotImplementedException();
73 }
74
75 public Task StsPolicyAsync(STSPolicy sts)
76 {
77 throw new NotImplementedException();
78 }
79
80 public Task ResumePolicyAsync(ResumePolicy resume)
81 {
82 throw new NotImplementedException();
83 }
84
85 public bool CapAgreed(ICapability capability)
86 {
87 throw new NotImplementedException();
88 }
89
90 public string CapAvailable(ICapability capability)
91 {
92 throw new NotImplementedException();
93 }
94
95 public Task<bool> SaslAuthAsync(SaslParams sasl)
96 {
97 throw new NotImplementedException();
98 }
99}
100
101public enum SendPriority
102{
103 High = 0,
104 Medium = 10,
105 Low = 20,
106 Default = Medium
107}
108public interface IServer
109{
110 Task<SentLine> SendRawAsync(string line, SendPriority priority = SendPriority.Default);
111 Task<SentLine> SendAsync(Line line, SendPriority priority = SendPriority.Default);
112
113 Task<Line> WaitForAsync();
114 void SetThrottle(int rate, float time);
115 (string, int) ServerAddress();
116
117 Task ConnectAsync(ITcpTransport transport, ConnectionParams connectionParams);
118 Task DisconnectAsync();
119
120 void LinePreread(Line line);
121 void LinePresend(Line line);
122 Task LineReadAsync(Line line);
123 Task LineSendAsync(Line line);
124 Task StsPolicyAsync(STSPolicy sts);
125 Task ResumePolicyAsync(ResumePolicy resume);
126
127 bool CapAgreed(ICapability capability);
128 string CapAvailable(ICapability capability);
129
130 Task<bool> SaslAuthAsync(SaslParams sasl);
131}
132
133public interface ITcpTransport
134{
135 (ITcpReader, ITcpWriter) Connect(string hostname, int port, Tls tls, string bindhost);
136}
137
138public interface ICapability
139{
140 string Available(IEnumerable<string> capabilities);
141 bool Match(string capability);
142 ICapability Copy();
143}
144
145public record struct SentLine(int Id, SendPriority Priority, Line Line);