コード例 #1
0
        public void CommandChannels(object sender, CommandEventArgs e)
        {
            IrcClient targetClient; string targetNickname;

            if (e.Parameters.Length == 2)
            {
                targetClient = null;
                foreach (ClientEntry clientEntry in Bot.Clients)
                {
                    IrcClient client = clientEntry.Client;
                    if (client.Address.Equals(e.Parameters[0], StringComparison.OrdinalIgnoreCase) || (client.Extensions.NetworkName ?? "").Equals(e.Parameters[0], StringComparison.OrdinalIgnoreCase))
                    {
                        targetClient = client;
                        break;
                    }
                }
                if (targetClient == null)
                {
                    e.Fail(string.Format("I'm not connected to \u0002{0}\u0002.", e.Parameters[0]));
                    return;
                }
                targetNickname = e.Parameters[1];
            }
            else
            {
                targetClient   = e.Client;
                targetNickname = e.Parameters[0];
            }

            e.Whisper(string.Join(" ", targetClient.Users[targetNickname].Channels.Select(channel => channel.Users[targetNickname].Status.GetPrefixes() + channel.Name)));
        }
コード例 #2
0
        public async void CommandDeleteAlias(object sender, CommandEventArgs e)
        {
            string  alias = e.Parameters[0];
            Command command;

            foreach (var pluginEntry in Bot.Plugins)
            {
                if (!pluginEntry.Obj.Commands.TryGetValue(alias, out command))
                {
                    continue;
                }

                // Check the scope.
                if ((command.Attribute.Scope & CommandScope.PM) == 0 && !(e.Target is IrcChannel))
                {
                    continue;
                }
                if ((command.Attribute.Scope & CommandScope.Channel) == 0 && e.Target is IrcChannel)
                {
                    continue;
                }

                // Check for permissions.
                string permission;
                if (command.Attribute.Permission == null)
                {
                    permission = null;
                }
                else if (command.Attribute.Permission != "" && command.Attribute.Permission.StartsWith("."))
                {
                    permission = this.Key + command.Attribute.Permission;
                }
                else
                {
                    permission = command.Attribute.Permission;
                }

                if (permission != null)
                {
                    if (!await Bot.CheckPermissionAsync(e.Sender, permission))
                    {
                        if (command.Attribute.NoPermissionsMessage != null)
                        {
                            e.Whisper(command.Attribute.NoPermissionsMessage);
                        }
                        return;
                    }
                }

                if (command.Attribute.Names.Count == 1)
                {
                    e.Fail("That's the only alias, and cannot be deleted.");
                    return;
                }

                pluginEntry.Obj.Commands.Remove(e.Parameters[0]);
                command.Attribute.Names.RemoveAll(name => name.Equals(e.Parameters[0], StringComparison.CurrentCultureIgnoreCase));
                e.Reply("Deleted the alias successfully.");

                return;
            }
        }