예제 #1
0
        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
                }
                    );
            }
                                         );
        }
예제 #2
0
        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.");
            }
                                         );
        }
예제 #3
0
 public override void OnCommand(CommandArguments command)
 {
     command.Reply("NYI");
 }
예제 #4
0
파일: Ban.cs 프로젝트: sgrassie/WendySharp
        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);
                }
            }
                                         );
        }
예제 #5
0
파일: Faq.cs 프로젝트: sgrassie/WendySharp
        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();
        }
예제 #6
0
        public override void OnCommand(CommandArguments command)
        {
            command.Reply("Farewell");

            Bootstrap.ResetEvent.Set();
        }