public override void OnCommand(CommandArguments command) { var nick = command.Arguments.Groups["nick"].Value; if (!IrcIdentity.TryParse(nick, out var ident)) { command.Reply("Invalid identity."); return; } var channel = Bootstrap.Client.ChannelList.GetChannel(command.Event.Recipient); if (!channel.WeAreOpped) { if (channel.HasChanServ) { Bootstrap.Client.Client.Message("ChanServ", string.Format("op {0}", channel.Name)); } else { command.Reply("I'm not opped, send help."); return; } } Bootstrap.Client.Whois.Query(ident, whoisData => { if (whoisData.Identity.Nickname != null) { ident = whoisData.Identity; } var nickname = ident.Nickname; if (nickname.ToString().ToLowerInvariant() == Bootstrap.Client.TrueNickname.ToLowerInvariant()) { command.Reply("Don't you even dare."); return; } if (whoisData.Identity.Nickname != null) { Whois.NormalizeIdentity(ident); } else { if (ident.Username == null) { ident.Username = "******"; } if (ident.Hostname == null) { ident.Hostname = "*"; } } var targetChannel = command.Arguments.Groups["channel"].Value.Trim(); if (targetChannel.Length == 0) { targetChannel = Bootstrap.Client.Settings.RedirectChannel; } else if (!IrcValidation.IsChannelName(targetChannel)) { command.Reply("Invalid target channel."); return; } if (Bootstrap.Client.ModeList.Find(command.Event.Recipient, ident.ToString(), "-b") != null) { command.Reply("{0} is already banned in this channel.", ident); return; } Log.WriteInfo("Redirect", "'{0}' redirected '{1}' from {2} to {3}", command.Event.Sender, ident, command.Event.Recipient, targetChannel); var reason = string.Format("Redirected to {0} by {1} for 2 hours", targetChannel, command.Event.Sender.Nickname); Bootstrap.Client.Client.Mode(command.Event.Recipient, "+b", ident + "$" + targetChannel); if (channel.HasUser(nickname)) { Bootstrap.Client.Client.Kick(nickname, command.Event.Recipient, reason); } command.ReplyAsNotice("Redirected {0} to {1} for 2 hours", ident, targetChannel); Bootstrap.Client.ModeList.AddLateModeRequest( new LateModeRequest { Channel = command.Event.Recipient, Recipient = ident.ToString(), Sender = command.Event.Sender.ToString(), Mode = "-b", Time = DateTime.UtcNow.AddHours(2), Reason = reason } ); } ); }
public override void OnCommand(CommandArguments command) { command.Reply("NYI"); }
public override void OnCommand(CommandArguments command) { var nick = command.Arguments.Groups["nick"].Value; if (nick.Length == 0 || !IrcIdentity.TryParse(nick, out var ident)) { ident = command.Event.Sender; } Bootstrap.Client.Whois.Query(ident, whoisData => { if (whoisData.Identity.Nickname == null) { command.Reply("There is no user by that nick on the network."); return; } ident = whoisData.Identity; if (string.Equals(ident.Nickname.ToString(), Bootstrap.Client.TrueNickname, StringComparison.InvariantCultureIgnoreCase)) { command.Reply("That's me, dummy."); return; } if (!Users.TryGetUser(ident, out var user)) { if (ident.Nickname == command.Event.Sender) { command.Reply("You have no permissions."); return; } command.Reply($"{ident.Nickname} has no permissions."); return; } var permissions = new List <string>(); if (user.Permissions.ContainsKey("*")) { permissions.AddRange(user.Permissions["*"]); } if (user.Permissions.ContainsKey(command.Event.Recipient)) { permissions.AddRange(user.Permissions[command.Event.Recipient]); } if (ident.Nickname == command.Event.Sender) { if (permissions.Count > 0) { command.Reply($"You have following permissions in this channel: {string.Join(", ", permissions.Distinct())}"); return; } command.Reply("You have no permissions in this channel."); return; } if (permissions.Count > 0) { command.Reply($"{ident.Nickname} has following permissions in this channel: {string.Join(", ", permissions.Distinct())}"); return; } command.Reply($"{ident.Nickname} has no permissions in this channel."); } ); }
public override void OnCommand(CommandArguments command) { var nick = command.Arguments.Groups["nick"].Value; if (!IrcIdentity.TryParse(nick, out var ident)) { command.Reply("Invalid identity."); return; } var duration = command.Arguments.Groups["duration"].Value; var durationTime = default(DateTime); if (duration.Length > 0) { try { durationTime = DateTimeParser.Parse(duration, command.Arguments.Groups["durationUnit"].Value); } catch (ArgumentException e) { command.Reply("{0}", e.Message); return; } } var channel = Bootstrap.Client.ChannelList.GetChannel(command.Event.Recipient); if (!channel.WeAreOpped) { if (channel.HasChanServ) { Bootstrap.Client.Client.IrcCommand("CHANSERV", "op", channel.Name); } else { command.Reply("I'm not opped, send help."); return; } } var isQuiet = command.MatchedCommand == "quiet" || command.MatchedCommand == "mute"; Bootstrap.Client.Whois.Query(ident, whoisData => { if (whoisData.Identity.Nickname == null) { command.Reply("There is no user by that nick on the network. Try {0}!*@* to {1} anyone with that nick, or specify a full hostmask.", ident.Nickname, isQuiet ? "quiet" : "ban"); return; } ident = whoisData.Identity; var nickname = ident.Nickname; if (string.Equals(nickname.ToString(), Bootstrap.Client.TrueNickname, StringComparison.InvariantCultureIgnoreCase)) { command.Reply("Don't you even dare."); return; } ident = Whois.NormalizeIdentity(ident); if (Bootstrap.Client.ModeList.Find(command.Event.Recipient, ident.ToString(), isQuiet ? "-q" : "-b") != null) { command.Reply("{0} is already {1} in this channel.", ident, isQuiet ? "muted" : "banned"); return; } Log.WriteInfo("Ban", "'{0}' {1} '{2}' from {3}", command.Event.Sender, isQuiet ? "quieted" : "banned", ident, command.Event.Recipient); var reason = command.Arguments.Groups["reason"].Value.Trim(); if (reason.Length == 0) { reason = $"Banned by {command.Event.Sender.Nickname}"; } Bootstrap.Client.Client.Mode(command.Event.Recipient, isQuiet ? "+q" : "+b", ident); if (!isQuiet && channel.HasUser(nickname)) { Bootstrap.Client.Client.Kick(nickname, command.Event.Recipient, reason); } if (duration.Length > 0) { command.ReplyAsNotice("Will {0} {1} {2}", isQuiet ? "unmute" : "unban", ident, durationTime.ToRelativeString()); Bootstrap.Client.ModeList.AddLateModeRequest( new LateModeRequest { Channel = command.Event.Recipient, Recipient = ident.ToString(), Sender = command.Event.Sender.ToString(), Mode = isQuiet ? "-q" : "-b", Time = durationTime, Reason = reason } ); } else { command.ReplyAsNotice("{0} {1}", isQuiet ? "Muted" : "Banned", ident); } } ); }
private void OnMessage(object obj, ChatMessageEventArgs e) { // Don't do anything in a private message if (!IrcValidation.IsChannelName(e.Recipient)) { return; } var message = e.Message.ToString().TrimEnd(); if (string.IsNullOrEmpty(message)) { return; } var isDirect = false; if (message.StartsWith(Bootstrap.Client.TrueNickname, StringComparison.InvariantCulture)) { var length = Bootstrap.Client.TrueNickname.Length; // "Wendy: " // Allow pinging with any character following bots name if (message.Length < length + 2 || message[length] == ' ' || message[length + 1] != ' ') { return; } message = message.Substring(length + 2); isDirect = true; } else if (message[0] == Bootstrap.Client.Settings.Prefix && Bootstrap.Client.Settings.Channels.Contains(e.Recipient)) { message = message.Substring(1); } else { return; } var match = CompiledCommandMatch.Match(message); if (!match.Success) { return; } var i = 1; while (match.Groups[i].Value.Length == 0) { i++; } var command = RegisteredCommands[i - 1]; Log.WriteInfo("CommandHandler", "Matched command '{0}' (as {2}) for {1}", command.Match.First(), e.Sender, match.Value); var arguments = new CommandArguments { IsDirect = isDirect, MatchedCommand = match.Value.Trim(), Event = e }; if (command.Permission != null) { // If there is no such user, don't pass if (!Users.TryGetUser(e.Sender, out var user)) { Log.WriteInfo("CommandHandler", "'{0}' is not a user I know of, can't perform '{1}' ({2})", e.Sender, arguments.MatchedCommand, command.Permission); return; } // If this user doesn't have required permission, don't pass if (!user.HasPermission(e.Recipient, command.Permission)) { Log.WriteInfo("CommandHandler", "'{0}' has no permission to perform '{1}' ({2})", e.Sender, arguments.MatchedCommand, command.Permission); return; } Log.WriteInfo("CommandHandler", "'{0}' is authorized to perform '{1}' ({2})", e.Sender, arguments.MatchedCommand, command.Permission); } if (command.CompiledMatch != null) { arguments.Arguments = command.CompiledMatch.Match(message); if (!arguments.Arguments.Success) { Help.PrintUsage(arguments, command); return; } } command.OnCommand(arguments); }
private void HandleModification(CommandArguments command, IReadOnlyList <string> cmd, bool isRemoval) { if (command.User?.HasPermission(command.Event.Recipient, Permission) != true) { command.Reply("You have no permission to use this command."); return; } if (!Commands.ContainsKey(command.Event.Recipient)) { Commands[command.Event.Recipient] = new SortedDictionary <string, string>(); } string trigger; if (isRemoval) { if (cmd.Count < 2) { command.Reply("Usage: ??remove <existing key>"); return; } trigger = cmd[1].ToLowerInvariant(); if (!Commands[command.Event.Recipient].ContainsKey(trigger)) { command.Reply($"No such FAQ entry: {trigger}"); return; } Commands[command.Event.Recipient].Remove(trigger); command.Reply($"Removed FAQ entry: {trigger}"); SaveToFile(); return; } if (cmd.Count < 3) { command.Reply("Usage: ??add <key> <value>"); return; } trigger = cmd[1].ToLowerInvariant(); if (trigger == "list" || trigger == "add" || trigger == "remove") { command.Reply("You can not add a reserved key word as a FAQ entry."); return; } command.Reply("{1} FAQ entry: {0}", trigger, Commands[command.Event.Recipient].ContainsKey(trigger) ? "Modified" : "Added"); Commands[command.Event.Recipient][trigger] = string.Join(" ", cmd.Skip(2)); SaveToFile(); }
public override void OnCommand(CommandArguments command) { command.Reply("Farewell"); Bootstrap.ResetEvent.Set(); }
/// <summary> /// Executed when an user calls this command. /// </summary> public abstract void OnCommand(CommandArguments command);