Skip to content

Commit 4290e42

Browse files
committed
...
1 parent 27739a3 commit 4290e42

4 files changed

Lines changed: 20 additions & 21 deletions

File tree

MedalBOT/BotContext.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ public class BotContext
6565
public Dictionary<string, DateTime> ServiceResponseTimeouts { get; set; }
6666
= new();
6767

68-
// Current active service request ID (one at a time)
69-
public string CurrentServiceRequestId { get; set; }
70-
7168
private readonly object _voicedLock = new();
7269
private readonly object _muteLock = new();
7370
private const string MutedIdsFile = "muted_ids.txt";

MedalBOT/Commands/ChanServCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public class ChanServCommand : ICommand
6565
private (bool, string) HandleBanList(BotContext ctx, string senderNick, bool isDiscord)
6666
{
6767
string commandId = $"blist_{DateTime.UtcNow.Ticks}_{senderNick}";
68-
ctx.CurrentServiceRequestId = commandId;
6968
ctx.TrackServiceRequest(commandId, senderNick, isDiscord);
69+
ctx.ServiceResponseTimeouts[commandId] = DateTime.UtcNow;
7070
ctx.Writer?.WriteLine($"PRIVMSG ChanServ :bans {ctx.Channel}");
7171
ctx.Logger?.Log($"[CHANSERV] {senderNick} requested banlist for {ctx.Channel} (ID: {commandId})");
7272
return (false, null);

MedalBOT/Commands/SpamServCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public class SpamServCommand : ICommand
7979
private (bool, string) HandleWordList(BotContext ctx, string senderNick, bool isDiscord)
8080
{
8181
string commandId = $"wordlist_{DateTime.UtcNow.Ticks}_{senderNick}";
82-
ctx.CurrentServiceRequestId = commandId;
8382
ctx.TrackServiceRequest(commandId, senderNick, isDiscord);
83+
ctx.ServiceResponseTimeouts[commandId] = DateTime.UtcNow;
8484
ctx.Writer?.WriteLine($"PRIVMSG SpamServ :listbadwords {ctx.Channel}");
8585
ctx.Logger?.Log($"[SPAMSERV] {senderNick} requested badwords list for {ctx.Channel} (ID: {commandId})");
8686
return (false, null);

MedalBOT/Program.cs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,23 +141,26 @@ static async Task Main()
141141
}
142142

143143
// Capture ChanServ/SpamServ NOTICE replies (sent to bot nick for service requests)
144-
if (line.Contains("NOTICE") && (line.Contains("ChanServ") || line.Contains("SpamServ")) && !string.IsNullOrWhiteSpace(ctx.CurrentServiceRequestId))
144+
if (line.Contains("NOTICE") && (line.Contains("ChanServ") || line.Contains("SpamServ")) && ctx.PendingServiceRequests.Count > 0)
145145
{
146146
string noticeContent = MessageParser.GetMessage(line);
147147
if (!string.IsNullOrWhiteSpace(noticeContent))
148148
{
149-
string requestId = ctx.CurrentServiceRequestId;
150-
151-
// Initialize buffer if needed
152-
if (!ctx.ServiceResponseBuffer.ContainsKey(requestId))
153-
ctx.ServiceResponseBuffer[requestId] = new System.Collections.Generic.List<string>();
154-
155-
// Add to buffer
156-
ctx.ServiceResponseBuffer[requestId].Add(noticeContent);
157-
ctx.Logger?.Log($"[SERVICE] Buffering response ({ctx.ServiceResponseBuffer[requestId].Count} lines): {noticeContent}");
149+
// Append to ALL active request buffers (ChanServ replies are sequential)
150+
foreach (var requestId in ctx.PendingServiceRequests.Keys.ToList())
151+
{
152+
// Initialize buffer if needed
153+
if (!ctx.ServiceResponseBuffer.ContainsKey(requestId))
154+
ctx.ServiceResponseBuffer[requestId] = new System.Collections.Generic.List<string>();
155+
156+
// Add to buffer
157+
ctx.ServiceResponseBuffer[requestId].Add(noticeContent);
158+
159+
// Update timeout for this request
160+
ctx.ServiceResponseTimeouts[requestId] = DateTime.UtcNow;
161+
}
158162

159-
// Reset timeout - update last received time
160-
ctx.ServiceResponseTimeouts[requestId] = DateTime.UtcNow;
163+
ctx.Logger?.Log($"[SERVICE] Buffering response to {ctx.PendingServiceRequests.Count} active request(s): {noticeContent}");
161164
}
162165
continue;
163166
}
@@ -178,13 +181,13 @@ static async Task Main()
178181
string requesterNick = requestInfo.RequesterNick;
179182
bool isDiscord = requestInfo.IsDiscord;
180183

181-
ctx.Logger?.Log($"[SERVICE TIMEOUT] Response complete: {responses.Count} lines for {requesterNick}");
184+
ctx.Logger?.Log($"[SERVICE TIMEOUT] Request {requestId} complete: {responses.Count} lines for {requesterNick}");
182185

183186
string fullResponse = string.Join("\n", responses);
184187

185188
if (isDiscord)
186189
{
187-
ctx.Logger?.Log($"[SERVICE RELAY] Sending to Discord...");
190+
ctx.Logger?.Log($"[SERVICE RELAY] Sending to Discord for {requesterNick}...");
188191
await ctx.Discord?.SendMessage($"**{requesterNick}**:\n```\n{fullResponse}\n```");
189192
}
190193
else
@@ -195,11 +198,10 @@ static async Task Main()
195198
}
196199
}
197200

198-
// Clean up
201+
// Clean up this specific request
199202
ctx.PendingServiceRequests.Remove(requestId);
200203
ctx.ServiceResponseBuffer.Remove(requestId);
201204
ctx.ServiceResponseTimeouts.Remove(requestId);
202-
ctx.CurrentServiceRequestId = null;
203205
}
204206
}
205207

0 commit comments

Comments
 (0)