public override void OnCommand(CommandArguments command) { // TODO: implement mask search //var mask = command.Arguments.Groups["mask"].Value; var modes = Bootstrap.Client.ModeList.GetModes().Where(x => x.Time != default).OrderBy(x => x.Time).ToList(); if (modes.Count == 0) { command.ReplyAsNotice("No pending unbans in this channel."); return; } foreach (var mode in modes) { command.ReplyAsNotice("In {0} setting {1} {2} {3}{4}", mode.Channel, mode.Mode, mode.Recipient, mode.Time.ToRelativeString(), mode.Sender == null ? "" : $" (from {mode.Sender})" ); } }
public static void PrintUsage(CommandArguments commandArguments, Command command, bool printAliases = false) { commandArguments.ReplyAsNotice("Usage: {0} {1}", command.Match.First(), command.Usage ?? "(no arguments)"); if (printAliases && command.Match.Count > 1) { commandArguments.ReplyAsNotice("Aliases: {0}", string.Join(", ", command.Match.Skip(1))); } commandArguments.ReplyAsNotice("{0}", command.HelpText ?? "No documentation provided (you're on your own!)"); }
public override void OnCommand(CommandArguments command) { var channel = Bootstrap.Client.ChannelList.GetChannel(command.Event.Recipient); // TODO: Check current channel modes if (channel.WeAreOpped) { Bootstrap.Client.Client.Mode(command.Event.Recipient, "+o", command.Event.Sender.Nickname); } else if (channel.HasChanServ) { // Op both the bot and sender Bootstrap.Client.Client.Message("ChanServ", string.Format("op {0} {1} {2}", channel.Name, Bootstrap.Client.TrueNickname, command.Event.Sender.Nickname)); } else { command.Reply("I'm not opped, send help."); return; } Log.WriteInfo("Moderated", "'{0}' made the '{1}' go into emergency mode", command.Event.Sender, command.Event.Recipient); Bootstrap.Client.Client.Mode(command.Event.Recipient, "+m"); command.ReplyAsNotice("Channel is now in LOCKDOWN mode. Only operators and voiced users may speak."); //command.ReplyAsNotice("Use {0}m again to undo and revert to normal", Bootstrap.Client.Settings.Prefix); }
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; } } var isQuiet = command.MatchedCommand != "unban"; Bootstrap.Client.Whois.Query(ident, whoisData => { if (whoisData.Identity.Nickname != null) { ident = whoisData.Identity; Whois.NormalizeIdentity(ident); } else { if (ident.Username == null) { ident.Username = "******"; } if (ident.Hostname == null) { ident.Hostname = "*"; } } Log.WriteInfo("Unban", "'{0}' unbanned '{1}' in {2}", command.Event.Sender, ident, command.Event.Recipient); Bootstrap.Client.Client.Mode(command.Event.Recipient, isQuiet ? "-q" : "-b", ident); command.ReplyAsNotice("{0} {1}", isQuiet ? "Unmuted" : "Unbanned", ident); } ); }
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; } if (string.Equals(ident.Nickname.ToString(), Bootstrap.Client.TrueNickname, StringComparison.InvariantCultureIgnoreCase)) { command.Reply("Don't you even dare."); 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 reason = command.Arguments.Groups["reason"].Value.Trim(); if (command.MatchedCommand == "duckoff" && reason.Length == 0) { reason = "Quack, motherducker"; } Log.WriteInfo("Kick", "'{0}' kicked '{1}' in {2} (reason: {3})", command.Event.Sender, ident, command.Event.Recipient, reason.Length == 0 ? "no reason given" : reason); if (command.MatchedCommand == "remove") { Bootstrap.Client.Client.Remove(ident.Nickname, command.Event.Recipient, reason.Length == 0 ? null : reason); } else { Bootstrap.Client.Client.Kick(ident.Nickname, command.Event.Recipient, reason.Length == 0 ? null : reason); } command.ReplyAsNotice("Kicked {0}", ident); }
public override void OnCommand(CommandArguments command) { if (!command.IsDirect) { return; } Users.TryGetUser(command.Event.Sender, out var user); var commands = Reference .GetRegisteredCommands() .Where(x => x.Permission == null || (user != null && user.HasPermission(command.Event.Recipient, x.Permission))) .ToList(); if (!commands.Any()) { return; } var matchedCommand = command.Arguments.Groups["command"].Value; if (matchedCommand.Length == 0) { var allowedCommands = commands.Select(x => x.Match.First()); command.ReplyAsNotice("Commands you have access to in this channel: {0}", string.Join(", ", allowedCommands)); return; } var foundCommand = commands.FirstOrDefault(x => x.Match.Contains(matchedCommand)); if (foundCommand == null) { command.ReplyAsNotice("That's not a command that I know of."); return; } PrintUsage(command, foundCommand, true); }
public override void OnCommand(CommandArguments command) { if (!command.IsDirect) { return; } var commands = Reference .GetRegisteredCommands() .Where(x => x.Permission == null || (command.User?.HasPermission(command.Event.Recipient, x.Permission) == true)) .ToList(); if (commands.Count == 0) { return; } var matchedCommand = command.Arguments.Groups["command"].Value; if (matchedCommand.Length == 0) { var allowedCommands = commands.Select(x => x.Match[0]).ToList(); allowedCommands.Add("??list"); command.ReplyAsNotice("Commands you have access to in this channel: {0}", string.Join(", ", allowedCommands)); return; } var foundCommand = commands.Find(x => x.Match.Contains(matchedCommand)); if (foundCommand == null) { command.ReplyAsNotice("That's not a command that I know of."); return; } PrintUsage(command, foundCommand, true); }
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) { 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); } } ); }