Skip to content

Commit 421c0f8

Browse files
committed
fix blist
1 parent 714db44 commit 421c0f8

3 files changed

Lines changed: 43 additions & 11 deletions

File tree

MedalBOT/BotContext.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public class BotContext
5757
public Dictionary<string, (string RequesterNick, bool IsDiscord)> PendingServiceRequests { get; set; }
5858
= new();
5959

60+
// Buffer for accumulating ChanServ responses
61+
public Dictionary<string, System.Collections.Generic.List<string>> ServiceResponseBuffer { get; set; }
62+
= new();
63+
6064
private readonly object _voicedLock = new();
6165
private readonly object _muteLock = new();
6266
private const string MutedIdsFile = "muted_ids.txt";

MedalBOT/Commands/ChanServCommand.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ public class ChanServCommand : ICommand
99

1010
public (bool handled, string response) Process(BotContext ctx, string senderNick, string message, string fullLine)
1111
{
12-
if (!message.StartsWith("!blist") && !message.StartsWith("!addban") &&
13-
!message.StartsWith("!delban") && !message.StartsWith("!tb"))
12+
// !blist is Discord-only, handled via ProcessDiscord
13+
// Only allow !addban, !delban, !tb from IRC
14+
if (!message.StartsWith("!addban") && !message.StartsWith("!delban") && !message.StartsWith("!tb"))
1415
return (false, null);
1516

1617
if (!ctx.Admins.Contains(senderNick))
1718
return (true, "You must be an admin to use ChanServ commands.");
1819

19-
if (message.StartsWith("!blist"))
20-
return HandleBanList(ctx, senderNick, false);
21-
2220
if (message.StartsWith("!addban"))
2321
return HandleAddBan(ctx, senderNick, message);
2422

@@ -33,6 +31,7 @@ public class ChanServCommand : ICommand
3331

3432
public (bool handled, string response) ProcessDiscord(BotContext ctx, string senderNick, string message)
3533
{
34+
// Discord can use !blist and other commands
3635
if (!message.StartsWith("!blist") && !message.StartsWith("!addban") &&
3736
!message.StartsWith("!delban") && !message.StartsWith("!tb"))
3837
return (false, null);
@@ -57,10 +56,10 @@ public class ChanServCommand : ICommand
5756

5857
private (bool, string) HandleBanList(BotContext ctx, string senderNick, bool isDiscord)
5958
{
60-
string commandId = $"blist_{DateTime.UtcNow.Ticks}";
59+
string commandId = $"blist_{DateTime.UtcNow.Ticks}_{senderNick}";
6160
ctx.TrackServiceRequest(commandId, senderNick, isDiscord);
6261
ctx.Writer?.WriteLine($"PRIVMSG ChanServ :bans {ctx.Channel}");
63-
ctx.Logger?.Log($"[CHANSERV] {senderNick} requested banlist for {ctx.Channel} (ID: {commandId})");
62+
ctx.Logger?.Log($"[CHANSERV] {senderNick} requested banlist for {ctx.Channel} (ID: {commandId}) - Discord: {isDiscord}");
6463
return (false, null);
6564
}
6665

@@ -110,3 +109,4 @@ public class ChanServCommand : ICommand
110109

111110

112111

112+

MedalBOT/Program.cs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,45 @@ static async Task Main()
147147
if (!string.IsNullOrWhiteSpace(noticeContent))
148148
{
149149
var lastRequest = ctx.PendingServiceRequests.LastOrDefault();
150-
if (lastRequest.Key != null && ctx.GetServiceRequest(lastRequest.Key, out string requesterNick, out bool isDiscord))
150+
if (lastRequest.Key != null)
151151
{
152-
ctx.Logger?.Log($"[CHANSERV RELAY] To {(isDiscord ? "Discord" : "IRC")}: {noticeContent}");
152+
// Accumulate responses in buffer
153+
if (!ctx.ServiceResponseBuffer.ContainsKey(lastRequest.Key))
154+
ctx.ServiceResponseBuffer[lastRequest.Key] = new System.Collections.Generic.List<string>();
155+
156+
ctx.ServiceResponseBuffer[lastRequest.Key].Add(noticeContent);
157+
ctx.Logger?.Log($"[CHANSERV] Buffering response: {noticeContent}");
158+
}
159+
}
160+
continue;
161+
}
162+
163+
// Check if we've received "end of response" from ChanServ (blank line or end marker)
164+
if (ctx.PendingServiceRequests.Count > 0 && !line.Contains("NOTICE") && !line.Contains("ChanServ"))
165+
{
166+
// Send accumulated responses
167+
var lastRequest = ctx.PendingServiceRequests.LastOrDefault();
168+
if (lastRequest.Key != null && ctx.ServiceResponseBuffer.ContainsKey(lastRequest.Key))
169+
{
170+
var responses = ctx.ServiceResponseBuffer[lastRequest.Key];
171+
if (responses.Count > 0 && ctx.GetServiceRequest(lastRequest.Key, out string requesterNick, out bool isDiscord))
172+
{
173+
string fullResponse = string.Join("\n", responses);
174+
ctx.Logger?.Log($"[CHANSERV RELAY] Sending {responses.Count} lines to {(isDiscord ? "Discord" : "IRC")}");
175+
153176
if (isDiscord)
154177
{
155-
await ctx.Discord?.SendMessage($"**{requesterNick}** - {noticeContent}");
178+
await ctx.Discord?.SendMessage($"**{requesterNick}** banlist:\n```\n{fullResponse}\n```");
156179
}
157180
else
158181
{
159-
writer.WriteLine($"PRIVMSG {ctx.Channel} :{noticeContent}");
182+
foreach (var resp in responses)
183+
{
184+
writer.WriteLine($"PRIVMSG {ctx.Channel} :{resp}");
185+
}
160186
}
187+
188+
ctx.ServiceResponseBuffer.Remove(lastRequest.Key);
161189
}
162190
}
163191
}

0 commit comments

Comments
 (0)