Skip to content

Commit c85f01b

Browse files
committed
fixes
1 parent a237261 commit c85f01b

5 files changed

Lines changed: 68 additions & 31 deletions

File tree

MedalBOT/Commands/MedalCommand.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ private static (bool, string) HandleMedal(BotContext ctx, string[] parts, string
4848
return (true, "Invalid medal type. Use: Platinum, Gold, or Silver.");
4949

5050
if (!ctx.CurrentHostmasks.TryGetValue(targetNick, out string hostmask) || string.IsNullOrWhiteSpace(hostmask))
51-
return (true, $"⚠️ Could not find hostmask for {targetNick}. Ask them to send a message or rejoin.");
51+
{
52+
ctx.Writer?.WriteLine($"WHO {targetNick}");
53+
ctx.Logger?.Log($"[MEDAL] Requesting WHO for {targetNick}");
54+
return (true, $"Fetching user info for {targetNick}...");
55+
}
5256

5357
string ident = ExtractIdent(hostmask);
5458
if (string.IsNullOrEmpty(ident)) return (true, "⚠️ Could not extract ident from hostmask.");
@@ -77,7 +81,11 @@ private static (bool, string) HandleUnmedal(BotContext ctx, string[] parts, stri
7781
string targetNick = parts[1];
7882

7983
if (!ctx.CurrentHostmasks.TryGetValue(targetNick, out string hostmask) || string.IsNullOrWhiteSpace(hostmask))
80-
return (true, $"⚠️ Could not find hostmask for {targetNick}.");
84+
{
85+
ctx.Writer?.WriteLine($"WHO {targetNick}");
86+
ctx.Logger?.Log($"[UNMEDAL] Requesting WHO for {targetNick}");
87+
return (true, $"Fetching user info for {targetNick}...");
88+
}
8189

8290
string ident = ExtractIdent(hostmask);
8391
if (string.IsNullOrEmpty(ident)) return (true, "⚠️ Could not extract ident from hostmask.");

MedalBOT/Commands/SayCommand.cs

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,8 @@ public class SayCommand : ICommand
99

1010
public (bool handled, string response) Process(BotContext ctx, string senderNick, string message, string fullLine)
1111
{
12-
if (!message.StartsWith("!say"))
13-
return (false, null);
14-
15-
if (!ctx.Admins.Contains(senderNick))
16-
return (true, "You must be an admin to use say commands.");
17-
18-
if (message.StartsWith("!sayto "))
19-
return HandleSayTo(ctx, senderNick, message);
20-
21-
if (message.StartsWith("!say "))
22-
return HandleSay(ctx, senderNick, message);
23-
12+
// !say and !sayto are Discord-only commands (Discord ? IRC only)
13+
// Not available from IRC channel
2414
return (false, null);
2515
}
2616

@@ -37,35 +27,32 @@ public bool TryHandleDiscordSay(BotContext ctx, string message)
3727
return false;
3828

3929
ctx.Writer?.WriteLine($"PRIVMSG {ctx.Channel} :{text}");
30+
ctx.Logger?.Log($"[DISCORD SAY] {text}");
4031
return true;
4132
}
4233

43-
private (bool, string) HandleSay(BotContext ctx, string senderNick, string message)
34+
public bool TryHandleDiscordSayTo(BotContext ctx, string message)
4435
{
45-
if (message.Length <= 5)
46-
return (true, "Usage: !say <message>");
47-
48-
string text = message.Substring(5).Trim();
49-
if (string.IsNullOrWhiteSpace(text))
50-
return (true, "Usage: !say <message>");
36+
if (!message.StartsWith("!sayto "))
37+
return false;
5138

52-
ctx.Logger?.Log($"[SAY] {senderNick} said: {text}");
53-
return (true, text);
54-
}
39+
if (!ctx.RelayDiscordToIrc)
40+
return false;
5541

56-
private (bool, string) HandleSayTo(BotContext ctx, string senderNick, string message)
57-
{
5842
var parts = message.Split(' ', StringSplitOptions.RemoveEmptyEntries);
5943
if (parts.Length < 3)
60-
return (true, "Usage: !sayto <nick> <message>");
44+
return false;
6145

6246
string targetNick = parts[1];
6347
string text = string.Join(" ", parts.Skip(2));
48+
if (string.IsNullOrWhiteSpace(text))
49+
return false;
6450

6551
ctx.Writer?.WriteLine($"PRIVMSG {targetNick} :{text}");
66-
ctx.Logger?.Log($"[SAYTO] {senderNick} sent PM to {targetNick}: {text}");
67-
return (false, null);
52+
ctx.Logger?.Log($"[DISCORD SAYTO] Sent PM to {targetNick}: {text}");
53+
return true;
6854
}
6955
}
7056
}
7157

58+

MedalBOT/Program.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,23 @@ static async Task Main()
134134

135135
await HostmaskTracker.UpdateHostmask(ctx, line);
136136

137+
// Parse WHO responses (IRC 352 code)
138+
if (line.Contains(" 352 "))
139+
{
140+
ParseWhoResponse(ctx, line);
141+
}
142+
143+
// Relay ChanServ/SpamServ NOTICE replies to channel
144+
if (line.Contains("NOTICE") && line.Contains("ChanServ"))
145+
{
146+
string message = MessageParser.GetMessage(line);
147+
if (!string.IsNullOrWhiteSpace(message))
148+
{
149+
writer.WriteLine($"PRIVMSG {ctx.Channel} :{message}");
150+
ctx.Logger?.Log($"[CHANSERV RELAY] {message}");
151+
}
152+
}
153+
137154
if (line.Contains(" QUIT "))
138155
{
139156
string quitter = MessageParser.GetNick(line);
@@ -277,5 +294,24 @@ private static void CheckExpiredMutes(BotContext ctx)
277294
ctx.Logger?.Log($"[MUTE EXPIRED] {systemId} mute expired");
278295
}
279296
}
297+
298+
private static void ParseWhoResponse(BotContext ctx, string line)
299+
{
300+
// IRC 352 format: :server 352 botnick channel ident host server nick H :hops realname
301+
// Example: :server 352 bot #channel ~ident host.com server nick H :0 Real Name
302+
var parts = line.Split(' ');
303+
if (parts.Length < 8) return;
304+
305+
string channel = parts[3];
306+
string ident = parts[4];
307+
string host = parts[5];
308+
string nick = parts[7];
309+
310+
if (string.IsNullOrWhiteSpace(nick) || nick.StartsWith(":")) return;
311+
312+
string hostmask = $"{ident}@{host}";
313+
ctx.CurrentHostmasks[nick] = hostmask;
314+
ctx.Logger?.Log($"[WHO] {nick}: {hostmask}");
315+
}
280316
}
281317
}

MedalBOT/Services/DiscordBotService.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,12 @@ private async Task OnMessageReceived(SocketMessage msg)
6767

6868
if (!_ctx.RelayDiscordToIrc) return;
6969

70+
// Handle Discord-to-IRC say commands
7071
if (_sayCommand.TryHandleDiscordSay(_ctx, content))
71-
{
7272
return;
73-
}
73+
74+
if (_sayCommand.TryHandleDiscordSayTo(_ctx, content))
75+
return;
7476
}
7577
}
7678
}

MedalBOT/Services/HostmaskTracker.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ public static async Task UpdateHostmask(BotContext ctx, string line)
2020
string hostmask = line.Substring(bang + 1, spaceAfter - bang - 1);
2121
string nick = MessageParser.GetNick(line);
2222

23+
// Skip IRC services (ChanServ, SpamServ, AuthServ, etc.)
24+
if (!string.IsNullOrWhiteSpace(nick) && (nick.EndsWith("Serv") || nick == "Services"))
25+
return;
26+
2327
if (!string.IsNullOrWhiteSpace(nick) && !string.IsNullOrWhiteSpace(hostmask))
2428
ctx.CurrentHostmasks[nick] = hostmask;
2529

0 commit comments

Comments
 (0)